File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -254,8 +254,10 @@ export function jsonToConvex(value: JSONValue): Value {
254254 return out ;
255255}
256256
257+ const MAX_VALUE_FOR_ERROR_LEN = 16384 ;
258+
257259export function stringifyValueForError ( value : any ) {
258- return JSON . stringify ( value , ( _key , value ) => {
260+ const str = JSON . stringify ( value , ( _key , value ) => {
259261 if ( value === undefined ) {
260262 // By default `JSON.stringify` converts undefined, functions, symbols,
261263 // Infinity, and NaN to null which produces a confusing error message.
@@ -270,6 +272,17 @@ export function stringifyValueForError(value: any) {
270272 }
271273 return value ;
272274 } ) ;
275+ if ( str . length > MAX_VALUE_FOR_ERROR_LEN ) {
276+ const rest = "[...truncated]" ;
277+ let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest . length ;
278+ const codePoint = str . codePointAt ( truncateAt - 1 ) ;
279+ if ( codePoint !== undefined && codePoint > 0xffff ) {
280+ // don't split a surrogate pair in half
281+ truncateAt -= 1 ;
282+ }
283+ return str . substring ( 0 , truncateAt ) + rest ;
284+ }
285+ return str ;
273286}
274287
275288function convexToJsonInternal (
You can’t perform that action at this time.
0 commit comments