Skip to content

Commit 337284e

Browse files
committed
refactor: change error message
1 parent 5d461de commit 337284e

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

brotli.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ static int php_brotli_compress_close(php_stream *stream,
645645
}
646646
} else {
647647
php_error_docref(NULL, E_WARNING,
648-
"brotli compress error");
648+
"brotli: failed to clean up compression");
649649
}
650650
}
651651

@@ -702,7 +702,7 @@ static ssize_t php_brotli_compress_write(php_stream *stream,
702702
php_stream_write(self->stream, output, out_size);
703703
}
704704
} else {
705-
php_error_docref(NULL, E_WARNING, "brotli compress error");
705+
php_error_docref(NULL, E_WARNING, "brotli: failed to compression");
706706
#if PHP_VERSION_ID >= 70400
707707
return -1;
708708
#endif
@@ -784,9 +784,18 @@ php_stream_brotli_opener(
784784
}
785785
if (level > BROTLI_MAX_QUALITY) {
786786
php_error_docref(NULL, E_WARNING,
787-
"brotli: compression level (%d) must be less than %d",
788-
level, BROTLI_MAX_QUALITY);
787+
"brotli: set compression level (%d)"
788+
" to BROTLI_COMPRESS_LEVEL_MAX:"
789+
" must be within %d..%d",
790+
level, BROTLI_MIN_QUALITY, BROTLI_MAX_QUALITY);
789791
level = BROTLI_MAX_QUALITY;
792+
} else if (level < BROTLI_MIN_QUALITY) {
793+
php_error_docref(NULL, E_WARNING,
794+
"brotli: set compression level (%d)"
795+
" to BROTLI_COMPRESS_LEVEL_DEFAULT:"
796+
" must be within %d..%d",
797+
level, BROTLI_MIN_QUALITY, BROTLI_MAX_QUALITY);
798+
level = BROTLI_DEFAULT_QUALITY;
790799
}
791800

792801
self = ecalloc(sizeof(*self), 1);
@@ -804,7 +813,7 @@ php_stream_brotli_opener(
804813
if (php_brotli_context_create_encoder(&self->ctx,
805814
level, 0, 0) != SUCCESS) {
806815
php_error_docref(NULL, E_WARNING,
807-
"brotli: compression context failed");
816+
"brotli: failed to prepare compression");
808817
php_stream_close(self->stream);
809818
efree(self);
810819
return NULL;
@@ -814,7 +823,7 @@ php_stream_brotli_opener(
814823
} else {
815824
if (php_brotli_context_create_decoder(&self->ctx) != SUCCESS) {
816825
php_error_docref(NULL, E_WARNING,
817-
"brotli: decompression context failed");
826+
"brotli: failed to prepare decompression");
818827
php_stream_close(self->stream);
819828
efree(self);
820829
return NULL;
@@ -1272,7 +1281,7 @@ static ZEND_FUNCTION(brotli_compress_add)
12721281
#endif
12731282
if (ctx == NULL || ctx->encoder == NULL) {
12741283
php_error_docref(NULL, E_WARNING,
1275-
"Brotli incremental compress resource failed");
1284+
"failed to prepare incremental compress");
12761285
RETURN_FALSE;
12771286
}
12781287

@@ -1301,7 +1310,7 @@ static ZEND_FUNCTION(brotli_compress_add)
13011310
efree(buffer);
13021311
smart_string_free(&out);
13031312
php_error_docref(NULL, E_WARNING,
1304-
"Brotli incremental compress failed");
1313+
"failed to incremental compress");
13051314
RETURN_FALSE;
13061315
}
13071316
}
@@ -1325,7 +1334,7 @@ static ZEND_FUNCTION(brotli_compress_add)
13251334
efree(buffer);
13261335
smart_string_free(&out);
13271336
php_error_docref(NULL, E_WARNING,
1328-
"Brotli incremental compress failed");
1337+
"failed to incremental compress");
13291338
RETURN_FALSE;
13301339
}
13311340
}
@@ -1356,8 +1365,7 @@ static ZEND_FUNCTION(brotli_uncompress)
13561365

13571366
BrotliDecoderState *state = BrotliDecoderCreateInstance(NULL, NULL, NULL);
13581367
if (!state) {
1359-
php_error_docref(NULL, E_WARNING,
1360-
"Invalid Brotli state");
1368+
php_error_docref(NULL, E_WARNING, "failed to prepare uncompress");
13611369
RETURN_FALSE;
13621370
}
13631371

@@ -1383,8 +1391,7 @@ static ZEND_FUNCTION(brotli_uncompress)
13831391
efree(buffer);
13841392

13851393
if (result != BROTLI_DECODER_RESULT_SUCCESS) {
1386-
php_error_docref(NULL, E_WARNING,
1387-
"Brotli decompress failed");
1394+
php_error_docref(NULL, E_WARNING, "failed to uncompress");
13881395
smart_string_free(&out);
13891396
RETURN_FALSE;
13901397
}
@@ -1403,7 +1410,7 @@ static ZEND_FUNCTION(brotli_uncompress_init)
14031410

14041411
if (php_brotli_context_create_decoder(ctx) != SUCCESS) {
14051412
php_error_docref(NULL, E_WARNING,
1406-
"Brotli incremental uncompress init failed");
1413+
"failed to prepare incremental uncompress");
14071414
RETURN_FALSE;
14081415
}
14091416
}
@@ -1452,7 +1459,7 @@ static ZEND_FUNCTION(brotli_uncompress_add)
14521459
#endif
14531460
if (ctx == NULL || ctx->decoder == NULL) {
14541461
php_error_docref(NULL, E_WARNING,
1455-
"Brotli incremental uncompress resource failed");
1462+
"failed to prepare incremental uncompress");
14561463
RETURN_FALSE;
14571464
}
14581465

0 commit comments

Comments
 (0)