Skip to content

Fix errors not printed#4116

Draft
hdiethelm wants to merge 5 commits into
LinuxCNC:masterfrom
hdiethelm:fix_errors_not_printed
Draft

Fix errors not printed#4116
hdiethelm wants to merge 5 commits into
LinuxCNC:masterfrom
hdiethelm:fix_errors_not_printed

Conversation

@hdiethelm
Copy link
Copy Markdown
Contributor

@hdiethelm hdiethelm commented Jun 3, 2026

This fixes #3948

The commit ddf60cd inhibits printing twice by always using old_handler() to print from motion and inhibits console print for motion->milltask messages. TBD if this is fine like this. Otherwise, I would just accept that errors are printed twice. Better than not at all.

Some options I tried and then discarded:

  • Add a flag to emcmot_error_t that shows if milltask is up and running and only invoke old_handler() if milltask is not running

    • When milltask is not yet running and then starts, the messages are still printed twice
    • When milltask dies between emcmotErrorPutfv() and the polling of the error buffer, nothing is shown
  • Inhinibit print to console by flag in milltask

    • This would need a flag in the dbuf struct which tells the milltask if the message was printed also with old_handler(). This dbuf looks complicated and it is bugprone if I change something here. Something like this would be needed while inhibitConsole is passed trough the dbuf:
  // read the emcmot error
    if (0 != usrmotReadEmcmotError(&inhibitConsole, errorString)) {
        // no error, so ignore
    } else {
        // an error to report
        // disable stdout print due to this error is from motion
        // and already printed to stdout
        if(inhibitConsole){
            RCS_PRINT_DESTINATION_TYPE prev_dest = get_rcs_print_destination();
            set_rcs_print_destination(RCS_PRINT_TO_NULL);
        }
        emcOperatorError("%s", errorString);
        if(inhibitConsole){
            set_rcs_print_destination(prev_dest);
        }
    }

hdiethelm added 4 commits June 3, 2026 13:40
The last two reverts fix the issue. This commit describes why there is
no good workaround against showing errors twice.
@hdiethelm hdiethelm force-pushed the fix_errors_not_printed branch from fce79d3 to ddf60cd Compare June 3, 2026 11:41
@hdiethelm
Copy link
Copy Markdown
Contributor Author

hdiethelm commented Jun 3, 2026

Meanwhile, I found a solution that doesn't print twice on the console. But the message in the console is not translated any more. See last commit ddf60cd

@BsAtHome Which version do you think is better?

In the below images, I first trigger an error using G2 I1000 F2000 which is printed with reportError(). Then I trigger loadrt pushmsg msgs="e|error|error" to show an rtapi error.

Before last commit:
grafik

After last commit:
grafik

Edit: There was a bug visible in the image. Fixed in force push.

Comment thread src/emc/motion/motion.c
Comment thread src/emc/motion/motion.c
Comment thread src/emc/task/taskintf.cc
@BsAtHome
Copy link
Copy Markdown
Contributor

BsAtHome commented Jun 3, 2026

Meanwhile, I found a solution that doesn't print twice on the console. But the message in the console is not translated any more.

Where in the chain is the translation performed?

@hdiethelm
Copy link
Copy Markdown
Contributor Author

hdiethelm commented Jun 3, 2026

Meanwhile, I found a solution that doesn't print twice on the console. But the message in the console is not translated any more.

Where in the chain is the translation performed?

I have no clue how this works. rcs_print() -> rcs_fputs() just does fputs(_str, stdout); and then it is translated. Might be some linker trick that overlays an stdout filter?

Instead of inhibiting old_handler() we always use old_handler() for
console in real time context and inhibit print to console for messages
passed from realtime to milltask.
@hdiethelm hdiethelm force-pushed the fix_errors_not_printed branch from ddf60cd to 9c1a6b2 Compare June 3, 2026 12:37
@hdiethelm
Copy link
Copy Markdown
Contributor Author

hdiethelm commented Jun 3, 2026

Meanwhile, I found a solution that doesn't print twice on the console. But the message in the console is not translated any more.

Where in the chain is the translation performed?

I have no clue how this works. rcs_print() -> rcs_fputs() just does fputs(_str, stdout); and then it is translated. Might be some linker trick that overlays an stdout filter?

Ah now, that one was well hidden:

Before this line it is untranslated, after it is translated:

result = snprintdbuf(e, EMCMOT_ERROR_LEN, &di);

The translation is here:
if(*fmt) fmt = gettext(fmt);

And if %s is used, it is here:
if(*s) s = gettext(s);

snprintdbuf() is a good name for translating text... ;-)

@hdiethelm
Copy link
Copy Markdown
Contributor Author

hdiethelm commented Jun 3, 2026

Tests with RTAI show one change:
Motion errors are now not shown anymore in terminal but in the kernel messages like all other real time errors.
The error is still shown in the GUI.

If desired, there is probably a way to enable the terminal errors for RTAI, but they are anyway shown in the GUI.

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.

Error messages are not shown if motmod is loaded and not started

2 participants