Skip to content

MUSE panics if processes are missing commodity flows #338

@alexdewar

Description

@alexdewar

If there are no commodity flows for a process, then you get panics like this:

thread 'main' panicked at src/input/process/pac.rs:101:43:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is a consequence of the refactoring I did in #323, which moved the check for process flows to here, after it's used in validate_pac_flows:

fn validate_pac_flows(
    pacs: &HashMap<Rc<str>, Vec<Rc<Commodity>>>,
    flows: &HashMap<Rc<str>, Vec<ProcessFlow>>,
) -> Result<()> {
    for (process_id, pacs) in pacs.iter() {
        // Get the flows for the process (unwrap is safe as every process has associated flows)
        let flows = flows.get(process_id).unwrap();

My bad. The good news is that we should fix this in the course of doing #337 anyway.

To reproduce

diff --git a/examples/simple/process_flows.csv b/examples/simple/process_flows.csv
index 459e75a..7790f3f 100644
--- a/examples/simple/process_flows.csv
+++ b/examples/simple/process_flows.csv
@@ -1,5 +1,4 @@
 process_id,commodity_id,flow,flow_type,flow_cost
-GASDRV,GASPRD,1.0,fixed,
 GASPRC,GASPRD,-1.05,fixed,
 GASPRC,GASNAT,1.0,fixed,
 WNDFRM,ELCTRI,1.0,fixed,
@@ -9,7 +8,6 @@ RGASBR,GASNAT,-1.15,fixed,
 RGASBR,RSHEAT,1.0,fixed,
 RELCHP,ELCTRI,-0.33,fixed,
 RELCHP,RSHEAT,1.0,fixed,
-GASDRV,CO2EMT,5.113,fixed,
 GASPRC,CO2EMT,2.5565,fixed,
 GASCGT,CO2EMT,76.695,fixed,
 RGASBR,CO2EMT,58.7995,fixed,

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions