Skip to content

Commit

Permalink
GCodeProcessor: enable waiting for moonraker
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Dec 4, 2024
1 parent b2c2351 commit d2d0b57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions configuration/klippy/ratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def _interpret_output(data):
self.console_echo(f"Post-processing ({data['payload']['percentage']}%)... {eta_str} remaining", 'info')
else:
self.console_echo(f"Post-processing ({data['payload']['percentage']}%)...", 'info')
if data['result'] == 'waiting':
self.console_echo('Post-processing waiting', 'info', 'Waiting for input file to finish being written...')

def _process_output(eventtime):
if process.stdout is None:
Expand Down
36 changes: 25 additions & 11 deletions src/cli/commands/postprocessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export const toPostProcessorCLIOutput = (obj: PostProcessorCLIOutput): void => {
};

class FileStillBeingWrittenError extends Error {
constructor(filePath: string) {
super(`Input file ${filePath} appears to still be being written to`);
constructor(filePath: string, maxWaitTime: number) {
super(`Input file ${filePath} appears to still be being written to after ${maxWaitTime}ms`);
}
}

Expand Down Expand Up @@ -196,9 +196,7 @@ const waitForFileToBeWritten = async (filePath: string, maxWaitTime: number = 10
}

if (attempts === maxAttempts) {
throw new FileStillBeingWrittenError(
`Input file ${filePath} appears to still be being written to after ${maxAttempts} seconds`,
);
throw new FileStillBeingWrittenError(filePath, maxWaitTime);
}
};

Expand All @@ -223,12 +221,28 @@ export const postprocessor = (program: Command) => {
try {
await waitForFileToBeWritten(inputFile);
} catch (e) {
toPostProcessorCLIOutput({
result: 'error',
title: 'Input file is still being written to',
message: `The input file ${inputFile} appears to still be being written to. Please wait for the file to finish being written and try again.`,
});
process.exit(1);
if (e instanceof FileStillBeingWrittenError) {
toPostProcessorCLIOutput({
result: 'error',
title: 'Input file is still being written to',
message: e.message,
});
process.exit(1);
} else if (e instanceof Error && 'code' in e && e.code === 'ENOENT' && 'path' in e) {
toPostProcessorCLIOutput({
result: 'error',
title: 'Input file not found',
message: e.message,
});
process.exit(1);
} else {
toPostProcessorCLIOutput({
result: 'error',
title: 'An unexpected error occurred while waiting for the input file to be written',
message: 'Please download a debug-zip and report this issue.',
});
throw e;
}
}

// load env variables
Expand Down

0 comments on commit d2d0b57

Please sign in to comment.