function set_object_in_file(file,obj) {
try {
- if (typeof(file)=='string') file = get_file( file );
- var f = create_output_stream(file);
- var obj_json = js2JSON( obj );
- f.write( obj_json, obj_json.length ); f.close();
+ if (obj) {
+ if (typeof(file)=='string') file = get_file( file );
+ var f = create_output_stream(file);
+ var obj_json = js2JSON( obj );
+ f.write( obj_json, obj_json.length ); f.close();
+ } else {
+ throw('Tried setting obj = ' + obj + '\n');
+ }
} catch(E) {
sdump('D_FILE', 'set_object_in_file: ' + js2JSON(E) + '\n');
throw(E);
if (typeof(file)=='string') file = get_file( file );
if (file.exists()) {
var f = create_input_stream(file);
- var obj = JSON2js( f.read(-1) );
+ var data = f.read(-1);
+ var obj = JSON2js( data );
f.close();
return obj;
} else {