Skip to content

Commit

Permalink
Added check for null root
Browse files Browse the repository at this point in the history
  • Loading branch information
technosf committed Sep 26, 2024
1 parent 2f16d0e commit 16f3cb0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Models/StationStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
* SPDX-FileCopyrightText: 2020-2022 Louis Brauer <[email protected]>
*/

// StationStore can store and retrieve a collection of stations
// in a JSON file
/**
StationStore
Store and retrieve a collection of stations in a JSON file
Uses libgee for data structures.
*/

using Gee;

Expand Down Expand Up @@ -63,9 +68,18 @@ public class StationStore : Object {
warning (@"store: unable to load data, does it exist? $(e.message)");
}

Json.Node node = parser.get_root ();
Json.Array array = node.get_array ();
array.foreach_element ((a, i, elem) => {
Json.Node? node = parser.get_root ();

if ( node == null )
{
debug ("store: unable to load data, root is null");
return; // FIXME What should be done when root node is null?
}

debug ("store: root is not null");

Json.Array array = node.get_array (); // Json-CRITICAL **: 21:02:51.821: json_node_get_array: assertion 'JSON_NODE_IS_VALID (node)' failed
array.foreach_element ((a, i, elem) => { // json_array_foreach_element: assertion 'array != NULL' failed
Station station = Json.gobject_deserialize (typeof (Station), elem) as Station;
// TODO This should probably not be here but in
// DirectoryController
Expand Down Expand Up @@ -130,4 +144,4 @@ public class StationStore : Object {
}
}

}
}

0 comments on commit 16f3cb0

Please sign in to comment.