Permalink
Browse files

AVRO-1160. C: Better error reporting in avrocat

Contributed by Lucas Martin-King.


git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1384549 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 124ed63 commit 13bb8b26f0d9b08baf3570ade1aa2a043b60d8b4 @dcreager dcreager committed Sep 13, 2012
Showing with 30 additions and 7 deletions.
  1. +3 −0 CHANGES.txt
  2. +27 −7 lang/c/src/avrocat.c
View
3 CHANGES.txt
@@ -67,6 +67,9 @@ Avro 1.7.2 (unreleased)
AVRO-1159. C: Check union discriminants in avro_value_read.
(Lucas Martin-King via dcreager)
+ AVRO-1160. C: Better error reporting in avrocat. (Lucas Martin-King
+ via dcreager)
+
Avro 1.7.1 (16 July 2012)
NEW FEATURES
View
34 lang/c/src/avrocat.c
@@ -30,21 +30,33 @@ static void
process_file(const char *filename)
{
avro_file_reader_t reader;
+ FILE *fp;
+ int should_close;
if (filename == NULL) {
- if (avro_file_reader_fp(stdin, "<stdin>", 0, &reader)) {
- fprintf(stderr, "Error opening <stdin>:\n %s\n",
- avro_strerror());
- exit(1);
- }
+ fp = stdin;
+ filename = "<stdin>";
+ should_close = 0;
} else {
- if (avro_file_reader(filename, &reader)) {
+ fp = fopen(filename, "rb");
+ should_close = 1;
+
+ if (fp == NULL) {
fprintf(stderr, "Error opening %s:\n %s\n",
- filename, avro_strerror());
+ filename, strerror(errno));
exit(1);
}
}
+ if (avro_file_reader_fp(fp, filename, 0, &reader)) {
+ fprintf(stderr, "Error opening %s:\n %s\n",
+ filename, avro_strerror());
+ if (should_close) {
+ fclose(fp);
+ }
+ exit(1);
+ }
+
avro_schema_t wschema;
avro_value_iface_t *iface;
avro_value_t value;
@@ -67,9 +79,17 @@ process_file(const char *filename)
avro_value_reset(&value);
}
+ if (!feof(fp)) {
+ fprintf(stderr, "Error: %s\n", avro_strerror());
+ }
+
avro_file_reader_close(reader);
avro_value_decref(&value);
avro_value_iface_decref(iface);
+
+ if (should_close) {
+ fclose(fp);
+ }
}

0 comments on commit 13bb8b2

Please sign in to comment.