Skip to content

1600 Better error handling when trying to simulate an empty project - #2572

Open
martastn wants to merge 7 commits into
masterfrom
1600-better-error-handling-when-trying-to-simulate-an-empty-project
Open

martastn wants to merge 7 commits into
masterfrom
1600-better-error-handling-when-trying-to-simulate-an-empty-project

Conversation

@martastn

@martastn martastn commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1600. Part of #2444.

Problem

An empty or incomplete project could be sent to the backend. There it failed with no explanation, hung for 5 minutes, or stayed RUNNING forever. Error log did not help either: the backend never stores log files, so it opened an empty tab and showed the same 404 toast three times.

Changes

  • findEmptyProjectReason: the run form checks the editor project before Start and shows the first missing piece under a disabled Start simulation:
    • the project is empty
    • a zone has no figures (SHIELD-HIT12A/FLUKA)
    • the World Zone has a zero size (SHIELD-HIT12A/FLUKA)
    • there is no material other than vacuum (SHIELD-HIT12A)
    • there is no output, or an output has no quantity, detector or zone
  • Error log: when the logs are missing, it closes the empty tab and shows one message. The request is not retried.

Screenshots

Before (master) After
Empty project before-empty-project after-empty-project
FLUKA, figures but no zones before-fluka-no-zones after-fluka-no-zones
Error log on a failed job before-error-log after-error-log

@martastn martastn self-assigned this Nov 28, 2026
@martastn
martastn marked this pull request as ready for review November 28, 2026 15:55
@grzanka

grzanka commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review

Close to ready: one real problem with the Error log toasts, the rest are nits. CI is green.

What I checked and found correct

  • Material check (SHIELD-HIT12A): the saved project lists only the materials that zones or the World Zone use, plus vacuum. So "everything is vacuum or black hole" really means the project has no material to simulate.
  • Zone outputs: treating an output that points at the World Zone as having no zone matches the editor, which doesn't offer the World Zone as a scoring target (getZoneOptionsForScoring).
  • World Zone size: the cylinder's innerRadius is left out of the size check, which is right because 0 is a valid inner radius. !(Number(value) > 0) also catches an empty or non-numeric value, not just 0.
  • Geant4 jobs: they always return an empty set of logs, so they now get the message instead of a blank tab, which is better.
  • Bundled examples: I ran the same checks on every example project for each simulator it's offered for (10 combinations). None are blocked.

Issues

  1. The user still sees two toasts, not one. The global ky afterResponse hook (src/services/AuthService.tsx, around lines 121-131) already shows the backend's message for every error response. For this request the backend answers 404 with "Logfiles are unavailable" (LogfilesResource.get in yaptide/routes/common_sim_routes.py). SimulationCardHelpers.ts then adds its own toast, "No log files are available for this simulation". retry: 0 fixed the three repeats but not the duplicate. The simplest fix is to add 'Logfiles are unavailable' to ignored_messages (src/services/AuthService.tsx:78). The other option is to show the new toast only when the backend returns an empty list.

  2. .catch(() => undefined) hides other errors (minor). A network failure or a 500 also ends with "No log files are available", which is misleading when trying to work out what went wrong. Consider catching only the 404 case, or saying "Could not load the log files" for other errors.

  3. The test uses the wrong cylinder type (nit). The World Zone's real cylinder is HollowCylinderGeometry, with parameters innerRadius, radius and depth. The test uses CylinderGeometry. It passes because the check looks at parameter names, but a test with the real shape, including innerRadius: 0, would cover the inner-radius exclusion.

  4. Simulator list duplicated (nit). [SimulatorType.SHIELDHIT, SimulatorType.FLUKA] already exists in RunSimulationForm.tsx:141, and the test defines it again as zoneSimulators. One shared constant would serve both (see the readability notes below).

  5. The block message updates only when the app redraws (fine for now). The form gets yaptideEditor?.toSerialized() from WrapperApp, so it is refreshed on redraw, not on every edit. That works today because editing happens in the Editor tab, which doesn't show the run form, and switching tabs redraws. If the run form ever appears next to the editor, the message would lag behind edits.

Readability suggestions (optional)

Writing the positive condition, giving it a name and negating it once makes these checks easier to follow:

const ZONE_SIMULATORS = [SimulatorType.SHIELDHIT, SimulatorType.FLUKA];

const usesZones = ZONE_SIMULATORS.includes(simulator);
if (!usesZones) return undefined;
const isPositiveNumber = (value: unknown) => Number(value) > 0;

const worldZoneHasSize = worldZoneSize.every(([, value]) => isPositiveNumber(value));

if (!worldZoneHasSize) {
	const hasZones = zones.length > 0;

	return hasZones
		? 'Set the World Zone size: enter its dimensions or use Calculate to fit it to the zones'
		: 'Set the World Zone size: enter its dimensions';
}

(Keep > 0 and not <= 0: NaN <= 0 is false, so an empty field would pass.)

const hasFigures = (zone: ZoneJSON) => (zone.unionOperations ?? []).flat().length > 0;
const zoneWithoutFigures = zones.find(zone => !hasFigures(zone));

const EMPTY_MATERIAL_ICRUS = [BLACK_HOLE_ICRU, VACUUM_ICRU];
const hasRealMaterial = materials.some(({ icru }) => !EMPTY_MATERIAL_ICRUS.includes(icru));
if (simulator === SimulatorType.SHIELDHIT && !hasRealMaterial) return '…';

Verdict: approve once issue 1 is fixed; the rest are optional.

Comment thread src/util/findEmptyProjectReason.ts Outdated
Comment on lines +21 to +22
if (simulator !== SimulatorType.SHIELDHIT && simulator !== SimulatorType.FLUKA)
return undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such logic conditions are undreadable to humans ....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the double !== is now ZONE_SIMULATORS.includes(simulator)

Comment thread src/util/findEmptyProjectReason.ts Outdated

if (
simulator === SimulatorType.SHIELDHIT &&
materialManager.materials.every(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add good comments explaining the idea of each check. Are you sure that pure vacuum simulations are not possible in shieldhit12a ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, each check now has a comment saying what goes wrong without it.

About vacuum: yes, I'm sure. On the local backend, a pure-vacuum SHIELD-HIT12A simulation stops with Error: mat.dat seems to be empty in the Docker logs of the simulation worker.

@martastn

martastn commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Fixed:

  1. 'Logfiles are unavailable' is now in ignored_messages, so a missing log shows only "No log files are available for this simulation".
  2. Only a 404 now means "no logs", other failures (like a 500 or a network error) say "Could not load the log files", and for a 500 the backend's own message still shows as well.
  3. The test now uses HollowCylinderGeometry with innerRadius. A new test checks that innerRadius: 0 with a positive radius is not blocked.
  4. Partly: the test now imports ZONE_SIMULATORS from findEmptyProjectReason. I didn't change RunSimulationForm or InputEditorPanel: there the list means "simulators a Common project can run in". It's the same list today, but it's a different rule.

Comment thread src/util/findEmptyProjectReason.ts Outdated
const { zoneManager, materialManager } = editorJson;
const zones: ZoneJSON[] = zoneManager.zones;

// A zone without figures has no shape: the job hangs until the 5-minute backend timeout.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems a bit weird, do you mean that "a project with empty zones (without any figures attached) is not supported by Fluka anD SHIELH-HIT12A, such simulation fails, therefore we detect that early here"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed.

Comment thread src/util/findEmptyProjectReason.ts Outdated

// mat.dat gets every material except vacuum and black hole. With nothing else
// it is empty and SHIELD-HIT12A stops with "mat.dat seems to be empty".
const hasRealMaterial = materialManager.materials.some(isRealMaterial);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should place if SHIELDHIT before that hasRealMaterial, it doesn't make sense to run that check for Fluka

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/util/findEmptyProjectReason.ts Outdated
if (simulator === SimulatorType.SHIELDHIT && !hasRealMaterial)
return 'SHIELD-HIT12A needs a material other than vacuum: add a zone or change the World Zone material';

// A World Zone without size makes the job hang until the backend timeout.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again "make job hangs" is useless, say rather what simulators support

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the comment now says that both simulators need a World Zone around the geometry, and that SHIELD-HIT12A hangs or stops with an error without one

Comment thread src/util/findEmptyProjectReason.ts Outdated
if (simulator === SimulatorType.SHIELDHIT && !hasRealMaterial)
return 'SHIELD-HIT12A needs a material other than vacuum: add a zone or change the World Zone material';

// A World Zone without size makes the job hang until the backend timeout.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the backend timeout is a bug of backend, it should report immediately of a problem

Comment thread src/util/findEmptyProjectReason.ts Outdated
// Without outputs there are no result files and the job fails.
if (outputs.length === 0) return 'Add an output with a quantity in the Scoring tab';

// One output without a quantity fails the whole SHIELD-HIT12A job.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment mentiones SHIELD-HIT12A , while the check seems to run for Fluka as well.
don't say about backend failing, mention how simulator behave

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the comment now covers both: SHIELD-HIT12A stops with an error, and FLUKA gives no result for that output

Comment thread src/util/findEmptyProjectReason.ts Outdated
if (outputWithoutQuantities)
return `Add a quantity to output "${outputWithoutQuantities.name}" or remove the output`;

// A missing detector or zone gives a 500 on submit or a job stuck in RUNNING.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, no comments on the backend

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the comment now only says how the simulators react

@grzanka grzanka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@grzanka

grzanka commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

The message "The project is empty: build the geometry in the Geometry tab and add an output with a quantity in the Scoring tab" is barely visible, can you expose it more ?

image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error handling when trying to simulate an empty project

2 participants