Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed May 28, 2024
1 parent 5c1f428 commit ce3e2f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/protect.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include <string>
#include <Rdefines.h>

#define STR(x) #x
#define STR(x) STR2(x)
#define STR2(x) #x

#define R_API_START() \
SEXP err_ = R_NilValue; \
Expand All @@ -18,7 +20,7 @@
} catch(std::string& ex) { \
strncpy(error_buffer_, ex.c_str(), sizeof(error_buffer_) - 1); \
} catch(...) { \
Rf_error("error in " STR(__FILE__) " @ " STR(__PRETTY_FUNCTION__)); \
Rf_error("nanoparquet error @ " __FILE__ ":" STR(__LINE__)); \
} \
if (!Rf_isNull(err_)) { \
R_ContinueUnwind(err_); \
Expand Down
28 changes: 21 additions & 7 deletions src/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ SEXP nanoparquet_read(SEXP filesxp) {
default:
auto it = parquet::format::_ConvertedType_VALUES_TO_NAMES.find(
s_ele->converted_type);
// TODO: better error message
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown FLBA type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" + __func__ + ")";
throw msg;

Check warning on line 192 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L188-L192

Added lines #L188 - L192 were not covered by tests
}
break;

Check warning on line 194 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L194

Added line #L194 was not covered by tests
}
Expand All @@ -198,7 +199,9 @@ SEXP nanoparquet_read(SEXP filesxp) {
default:
auto it = parquet::format::_Type_VALUES_TO_NAMES.find(
f.columns[col_idx]->type);
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown column type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" + __func__ + ")";
throw msg;

Check warning on line 204 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L199-L204

Added lines #L199 - L204 were not covered by tests
}
SET_VECTOR_ELT(retlist, col_idx, varvalue);
UNPROTECT(1); /* varvalue */
Expand Down Expand Up @@ -258,7 +261,10 @@ SEXP nanoparquet_read(SEXP filesxp) {
default:
auto it = parquet::format::_ConvertedType_VALUES_TO_NAMES.find(
s_ele->converted_type);
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown column type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" +
__func__ + ")";
throw msg;

Check warning on line 267 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L264-L267

Added lines #L264 - L267 were not covered by tests
}
break;
}
Expand All @@ -270,7 +276,10 @@ SEXP nanoparquet_read(SEXP filesxp) {
default: {
auto it = parquet::format::_Type_VALUES_TO_NAMES.find(
f.columns[col_idx]->type);
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown column type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" +
__func__ + ")";
throw msg;

Check warning on line 282 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L279-L282

Added lines #L279 - L282 were not covered by tests
}
}
continue;
Expand Down Expand Up @@ -334,7 +343,10 @@ SEXP nanoparquet_read(SEXP filesxp) {
default:
auto it = parquet::format::_ConvertedType_VALUES_TO_NAMES.find(
s_ele->converted_type);
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown FLBA type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" +
__func__ + ")";
throw msg;

Check warning on line 349 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L342-L349

Added lines #L342 - L349 were not covered by tests
break;
}
}
Expand All @@ -347,7 +359,9 @@ SEXP nanoparquet_read(SEXP filesxp) {
default: {
auto it = parquet::format::_Type_VALUES_TO_NAMES.find(
f.columns[col_idx]->type);
throw np_error({ uwtoken });
string msg = string("nanoparquet_read: Unknown column type ") +
it->second + " @ " __FILE__ ":" STR(__LINE__) " (" + __func__ + ")";
throw msg;

Check warning on line 364 in src/read.cpp

View check run for this annotation

Codecov / codecov/patch

src/read.cpp#L359-L364

Added lines #L359 - L364 were not covered by tests
}
}
}
Expand Down

0 comments on commit ce3e2f9

Please sign in to comment.