Mailing List Archive

[interchange] Tag import-fields: make error handling more robust
commit ff51f5720164b94d02369791d139a38430f7e235
Author: Jon Jensen <jon@endpoint.com>
Date: Wed Nov 1 18:56:30 2017 -0600

Tag import-fields: make error handling more robust

Some database types' set_slice do not eval, and thus do not reliably
set $@ so we should clear it first.

Include $@ if it is set. This is still messy, because an unrelated eval
in set_slice or something it calls could leave a bogus error, but without
rewriting every set_slice completely, this is the best we can do.

The set_slice method returns undef on failure or a new key on success,
so check for that instead.

code/UI_Tag/import_fields.coretag | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/code/UI_Tag/import_fields.coretag b/code/UI_Tag/import_fields.coretag
index 11848e8..b7cedf9 100644
--- a/code/UI_Tag/import_fields.coretag
+++ b/code/UI_Tag/import_fields.coretag
@@ -1,4 +1,4 @@
-# Copyright 2002-2007 Interchange Development Group and others
+# Copyright 2002-2009 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -7,7 +7,7 @@

UserTag import_fields Order table
UserTag import_fields addAttr
-UserTag import_fields Version $Revision: 1.15 $
+UserTag import_fields Version 1.16
UserTag import_fields Routine <<EOR
sub {
my($table, $opt) = @_;
@@ -421,13 +421,18 @@ EOF
}
}

- $db->set_slice($k, \%hash) if @names;
+ if (@names) {
+ undef $@;
+ my $key = $db->set_slice($k, \%hash);
+ unless ($key) {
+ my $msg_raw = "error on update";
+ $msg_raw .= ": $@" if $@;
+ my $msg = ::errmsg($msg_raw);
+ ::logError($msg);
+ $out .= $msg;
+ }
+ }

- if($@) {
- my $msg = ::errmsg("error on update: %s", $@);
- ::logError($msg);
- $out .= $msg;
- }
$count++;
}


_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs