[Solved] LuCI - how to show error message

Hi, I struggle changing a luci module to show an error message. Are there facilities to show a message? (from inside a hook - but it does not matter really)

Well, depending on your needs and UI workflow you have different options. Here are a few:

  • You could include a message in your rendered page:
m = Map("my-uci-config")
     (... tested that something bad happened ...)
m.message = translate("Woe betide us! Something bad happened!")
  • or you could abort the page render using an assertion and display a stack trace and your message:
assert(luci.util.instanceof(cbi_obj, cbi.AbstractValue),
                "Object not in AbstractValue class")
  • or you could write a message to stderr:
luci.util.perror("LUCI TEST SYSLOG")

which will appear in your syslog, for example:

Mon Oct 29 17:03:31 2018 daemon.err uhttpd[2072]: LUCI TEST SYSLOG

Hope that helps...

Thanks, I did not know about m.message.

If your question is answered, please consider marking this topic as [Solved]. (Click the pencil behind the topic...)

No problem. I had to figure this all out a year ago so it's still all fresh :wink:. Would you mind marking my post above as the solution too? Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.