Browse Source

Improve encode/decode error messages

pull/1738/head
Sami Vaarala 7 years ago
parent
commit
44534e0385
  1. 2
      src-input/duk_api_bytecode.c
  2. 6
      src-input/duk_api_codec.c
  3. 2
      src-input/duk_bi_encoding.c
  4. 4
      src-input/duk_lexer.c
  5. 8
      src-input/duk_strings.h

2
src-input/duk_api_bytecode.c

@ -747,7 +747,7 @@ DUK_EXTERNAL void duk_load_function(duk_hthread *thr) {
return;
format_error:
DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE);
}
#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */

6
src-input/duk_api_codec.c

@ -410,7 +410,7 @@ DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) {
return ret;
type_error:
DUK_ERROR_TYPE(thr, DUK_STR_ENCODE_FAILED);
DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED);
return NULL; /* never here */
}
@ -454,7 +454,7 @@ DUK_EXTERNAL void duk_base64_decode(duk_hthread *thr, duk_idx_t idx) {
return;
type_error:
DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED);
}
DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) {
@ -593,7 +593,7 @@ DUK_EXTERNAL void duk_hex_decode(duk_hthread *thr, duk_idx_t idx) {
return;
type_error:
DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED);
}
#if defined(DUK_USE_JSON_SUPPORT)

2
src-input/duk_bi_encoding.c

@ -330,7 +330,7 @@ DUK_LOCAL duk_ret_t duk__decode_helper(duk_hthread *thr, duk__decode_context *de
return 1;
fail_type:
DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_TYPE(thr, DUK_STR_UTF8_DECODE_FAILED);
DUK_UNREACHABLE();
}

4
src-input/duk_lexer.c

@ -312,7 +312,7 @@ DUK_LOCAL void duk__fill_lexer_buffer(duk_lexer_ctx *lex_ctx, duk_small_uint_t s
lex_ctx->input_offset = (duk_size_t) (p - lex_ctx->input);
lex_ctx->input_line = input_line;
DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED);
}
DUK_LOCAL void duk__advance_bytes(duk_lexer_ctx *lex_ctx, duk_small_uint_t count_bytes) {
@ -472,7 +472,7 @@ DUK_LOCAL duk_codepoint_t duk__read_char(duk_lexer_ctx *lex_ctx) {
error_clipped: /* clipped codepoint */
error_encoding: /* invalid codepoint encoding or codepoint */
DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_DECODE_FAILED);
DUK_ERROR_SYNTAX(lex_ctx->thr, DUK_STR_SOURCE_DECODE_FAILED);
return 0;
}

8
src-input/duk_strings.h

@ -62,8 +62,12 @@
#define DUK_STR_BUFFER_TOO_LONG "buffer too long"
#define DUK_STR_ALLOC_FAILED "alloc failed"
#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type"
#define DUK_STR_ENCODE_FAILED "encode failed"
#define DUK_STR_DECODE_FAILED "decode failed"
#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed"
#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed"
#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed"
#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed"
#define DUK_STR_HEX_DECODE_FAILED "hex decode failed"
#define DUK_STR_INVALID_BYTECODE "invalid bytecode"
#define DUK_STR_NO_SOURCECODE "no sourcecode"
#define DUK_STR_RESULT_TOO_LONG "result too long"
#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc"

Loading…
Cancel
Save