Changeset: bf7c6ef65a6d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf7c6ef65a6d
Modified Files:
        clients/examples/C/streamcat.c
        common/stream/iconv_stream.c
Branch: Oct2020
Log Message:

Better error handling when iconv_open fails


diffs (56 lines):

diff --git a/clients/examples/C/streamcat.c b/clients/examples/C/streamcat.c
--- a/clients/examples/C/streamcat.c
+++ b/clients/examples/C/streamcat.c
@@ -191,8 +191,10 @@ int cmd_read(char *argv[])
                }
                if (wrapper != NULL)
                        s = wrapper(s, parms);
-               if (s == NULL)
-                       croak(2, "Wrapper %s did not return a stream", 
wrapper_name);
+               if (s == NULL || mnstr_errnr(s)) {
+                       char *msg = mnstr_error(s);
+                       croak(2, "Opener %s failed: %s", opener_name, msg ? msg 
: "<no error message>");
+               }
        }
 
        if (out == NULL) {
@@ -300,8 +302,10 @@ int cmd_write(char *argv[])
                }
                if (wrapper != NULL)
                        s = wrapper(s, parms);
-               if (s == NULL)
-                       croak(2, "Wrapper %s did not return a stream", 
wrapper_name);
+               if (s == NULL || mnstr_errnr(s)) {
+                       char *msg = mnstr_error(s);
+                       croak(2, "Opener %s failed: %s", opener_name, msg ? msg 
: "<no error message>");
+               }
        }
 
        if (in == NULL) {
diff --git a/common/stream/iconv_stream.c b/common/stream/iconv_stream.c
--- a/common/stream/iconv_stream.c
+++ b/common/stream/iconv_stream.c
@@ -292,8 +292,10 @@ iconv_rstream(stream *restrict ss, const
        if (ss->isutf8)
                return ss;
        cd = iconv_open("utf-8", charset);
-       if (cd == (iconv_t) -1)
+       if (cd == (iconv_t) -1) {
+               mnstr_set_open_error(name, errno, "iconv_open");
                return NULL;
+       }
        s = ic_open(cd, ss, name);
        if (s == NULL) {
                iconv_close(cd);
@@ -318,8 +320,10 @@ iconv_wstream(stream *restrict ss, const
        if (ss->isutf8)
                return ss;
        cd = iconv_open(charset, "utf-8");
-       if (cd == (iconv_t) -1)
+       if (cd == (iconv_t) -1) {
+               mnstr_set_open_error(name, errno, "iconv_open");
                return NULL;
+       }
        s = ic_open(cd, ss, name);
        if (s == NULL) {
                iconv_close(cd);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to