4242import com .google .gson .JsonParser ;
4343import com .google .gson .JsonPrimitive ;
4444
45+ import tlc2 .output .EC ;
46+ import tlc2 .tool .EvalException ;
4547import tlc2 .value .IValue ;
48+ import tlc2 .value .Values ;
4649import tlc2 .value .impl .BoolValue ;
4750import tlc2 .value .impl .FcnLambdaValue ;
4851import tlc2 .value .impl .FcnRcdValue ;
@@ -144,7 +147,11 @@ public static IValue deserialize(final StringValue path) throws IOException {
144147 */
145148 @ TLAPlusOperator (identifier = "ndJsonSerialize" , module = "Json" , warn = false )
146149 public synchronized static BoolValue ndSerialize (final StringValue path , final Value v ) throws IOException {
147- TupleValue value = (TupleValue ) v .toTuple ();
150+ final TupleValue value = (TupleValue ) v .toTuple ();
151+ if (value == null ) {
152+ throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
153+ new String [] { "second" , "ndJsonSerialize" , "sequence" , Values .ppr (v .toString ()) });
154+ }
148155 File file = new File (path .val .toString ());
149156 if (file .getParentFile () != null ) {file .getParentFile ().mkdirs ();} // Cannot create parent dir for relative path.
150157 try (BufferedWriter writer = new BufferedWriter (new FileWriter (new File (path .val .toString ())))) {
@@ -164,7 +171,11 @@ public synchronized static BoolValue ndSerialize(final StringValue path, final V
164171 */
165172 @ TLAPlusOperator (identifier = "JsonSerialize" , module = "Json" , warn = false )
166173 public synchronized static BoolValue serialize (final StringValue path , final Value v ) throws IOException {
167- TupleValue value = (TupleValue ) v .toTuple ();
174+ final TupleValue value = (TupleValue ) v .toTuple ();
175+ if (value == null ) {
176+ throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
177+ new String [] { "second" , "JsonSerialize" , "sequence" , Values .ppr (v .toString ()) });
178+ }
168179 File file = new File (path .val .toString ());
169180 if (file .getParentFile () != null ) {file .getParentFile ().mkdirs ();} // Cannot create parent dir for relative path.
170181 try (BufferedWriter writer = new BufferedWriter (new FileWriter (new File (path .val .toString ())))) {
0 commit comments