What' the quickest way to display a message similar to MsgBox in C# ?
I've tried this:
Base.Document.View.Ask("Hello World", MessageButtons.OK);
It publishes but I'm getting an error when it executes.
For that use case, throwing an exception will be enough:
throw new PXException("Hello World");
It uses the browser themed message box:
For debugging I prefer using traces:
PXTrace.WriteInformation("Hello World");
Message will appear in the trace window:
You can open the trace window in the help menu from most Acumatica screens:
Related
I use the ace editor with the vim keybindings on my site. Whenever someone goes into normal mode and types a command, it shows up in a dialog at the bottom. I defined a function like so:
ace.config.loadModule("ace/keyboard/vim", m => {
m.CodeMirror.Vim.defineEx("write", "w", () => submitForm())
})
The neat thing is, whenever that function errors, it shows the error in another dialog. My question is, is this feature exposed to users? Can I use that dialog to show messages like the editor does when the function errors? Here's a screenshot to show an example:
Typing a command -
Error pops up (another dialog in front of the one that I use to type the command) -
there is no documented api for this, but judging by
https://github.com/ajaxorg/ace/blob/v1.4.9/lib/ace/keyboard/vim.js#L4983, it should be possible to use the following
editor.state.cm.openNotification(domNodeOrHtmlString, {bottom: true, duration: 5000})
to create the dom node you can use the buildDom function from ace.
var domNode = ace.require("ace/lib/dom").buildDom(["span", {style: "color:red"}, "xxxxx"])
I use Laravel 5.6 and PostgreSQL 11 in order to import data from Excel file to database. How do I customize the sqlstate error message coming from postgres and display it to user?
You should capture the exception and treat it accordingly.
An SQLState error can be captured with a catch (\Exception $e).
Check this link to learn about php exceptions if you don't know yet.
Check this other link on error handling to learn how to deal with exceptions accordingly in Laravel.
You can customize your exception using try catch.
try {
//your source code (import excel to database)
} catch(\Exception $e) {
return "your customize message put here";
}
I wanted to know does YUI3 provides any way to try and catch errors functionality, where in after the error is captured we can show some customized error alert and simultaneously log the error at server side with the error exceptions and other details.
Also if this functionality is not there in yui3 then which all frameworks do one need to use to do this and which all are compatible with YUI.
I'm not aware of YUI3 providing exactly what you're after out-of-the box.
You can split your question into two parts:
Capturing errors
You either wrap your code with try/catch blocks or use a global error handler. It looks like YUI3 doesn't yet directly handle this (http://yuilibrary.com/projects/yui3/ticket/2528067) but handling it shouldn't be too hard, you'll just have to test for browser differences.
Sending Error data to the server
You ought to be able to use Y.IO to send back the error data to the server. It looks like you get errorMsg, url, lineNumber given to you, so you can just send them back to the server:
YUI().use("io-base",function(Y){
window.onerror = function(errorMsg, url, lineNumber){
Y.io("/errorHandler.php", {
data: {
errorMsg: errorMsg,
url: url,
lineNumber: lineNumber
}
});
alert("Sorry, something bad happened");
};
console.log("handler registered");
//now trigger an error
a.b.c="banana";
});
That seems to work here: http://jsfiddle.net/J83LW/
I'l leave the customized alert to you, I've left an alert here as a basic example of handling this
I'm trying to generate a custom error page for my xpages. I googled a lot of solutions and so far I get an error page telling me, that an error occured.
But I can't get the information what exactly happened (in this case the error is, that an "doc" has to be saved, but i named the variable "docs" just to get error).
All I do is:
var errObj = requestScope.error;
output = errObj.getCause().getErrorPropertyId();
output = errObj.getCause().getComponentId();
As soon as I try to call getExpressionText() I get an error 500.
How do I get the information, where the error happened (line number) and the variable that caused the error? - just like I do using the standard error page.
The error line and details are not easily accessible from requestScope.error. If you look at the source code for the latest release of Mark Leusink's Debug Toolbar, you'll see he's parsing the stack trace to get the details.
However, you can access all the relevant information using the underlying Java class for the SSJS exception - com.ibm.jscript.InterpretException using getErrorLine(). The getLocalizedMessage() method gets the error detail that usually starts "Script interpreter error". The getExpressionText() method retrieves the line that threw the error.
If you take a look at the XPages OpenLog Logger project I put on OpenNTF, that's what I use to log full details to OpenLog. http://www.openntf.org/Internal/home.nsf/project.xsp?action=openDocument&name=XPages%20OpenLog%20Logger
You can see the source code of the OpenLogPhaseListener which uses those methods here: https://github.com/paulswithers/openlogjava/blob/master/OpenLogJava/WebContent/WEB-INF/src/com/paulwithers/openLog/OpenLogPhaseListener.java
Even if you're not a Java expert, from use of SSJS the key parts should be understandable. Line 84 captures uncaught exceptions - when XPages routes to the default error page. That uses the methods I mentioned.
Lines 98 to 105 are the ones that log out all the details if you just use a catch block, passing OpenLogBean.addError(e, this) where e is the error object and this is the component the error occurs on. error.getError() in the Java code retrieves that error object. To get the typeahead in SSJS you'll need to use catch(e:com.ibm.jscript.InterpretException) I believe.
I haven't tested this, I've just working back from what I used for the project on OpenNTF.
Have a look at this XSnippet by Tony McGuckin: http://openntf.org/XSnippets.nsf/snippet.xsp?id=custom-error-page-cw-cause-and-stacktrace-information. It uses the following to output details on the error:
var output = requestScope.error.toString()+"\n\n";
if(requestScope.error instanceof com.ibm.xsp.exception.XSPExceptionInfo){
var codeSnippet = requestScope.error.getErrorText();
var control = requestScope.error.getErrorComponentId();
var cause = requestScope.error.getCause();
output += "In the control : " + control + "\n\n";
if(cause instanceof com.ibm.jscript.InterpretException){
var errorLine = cause.getErrorLine();
var errorColumn = cause.getErrorCol();
output += "At line " + errorLine;
output += ", column " + errorColumn + " of:\n";
}else{
output += "In the script:\n";
}
output += codeSnippet;
}
return output;
For now I've dealt with this problem by using the Debug Toolbar and the OpenLog Database.
If an error occurs the user only gets a custom error page (using the example of the Debug Toolbar) with the information, that something went wrong. So he does not have to bother with any other problems or even the Stack Trace. But at the same moment he gets the error page, the error is logged in our Log-Database with all informations needed (like line, exact error message etc.).
I've also implemented an "Report this problem" Link-Button to create a new E-Mail containing important information about the session the user is currently in.
I just read that new Watir version (3.1.0) has "support for Alert API". What can I actually do with this API?
Is it meant for dealing with javascript popup windows? If so, what command can I use to click "OK" in popup window? Or how can I read title & text of popup window?
I tried "browser.alert.ok" after updating Watir to 3.1.0 but just got some error message...
(There is not yet any clear documentation about this, and trying to interpret the source code is not my strongest side...)
Alert API is for dealing with JavaScript popups.
browser.alert.ok should work. Could you provide the error message?
I am not sure about getting popup title, but you can get it's text with browser.alert.text
More information: http://watir.github.io/docs/javascript-dialogs/
browser.alert.ok should work. Could you provide the error message?
Sure. First, here is Watir code that I used:
require 'watir'
b = Watir::Browser.start "www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
b.maximize
b.frame(:name, "view").button(:text, "Show alert box").click_no_wait
sleep 2
b.alert.ok
And here is the error message:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:319: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
-- control frame ----------
c:0012 p:---- s:0052 b:0052 l:000051 d:000051 CFUNC :enum_child_windows
c:0011 p:0065 s:0046 b:0046 l:002478 d:002478 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:319
c:0010 p:0015 s:0038 b:0038 l:0018e4 d:0018e4 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:200
c:0009 p:0025 s:0033 b:0033 l:000032 d:000032 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:147
c:0008 p:0035 s:0025 b:0024 l:000023 d:000023 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/window.rb:247
c:0007 p:0017 s:0020 b:0020 l:000019 d:000019 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/rautomation-0.7.2/lib/rautomation/window.rb:220
c:0006 p:---- s:0015 b:0015 l:000014 d:000014 FINISH
c:0005 p:0079 s:0013 b:0013 l:000012 d:000012 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialogs/alert.rb:38
c:0004 p:0011 s:0010 b:0010 l:000009 d:000009 METHOD C:/Ruby192/lib/ruby/gems/1.
9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialogs/alert.rb:27
c:0003 p:0107 s:0007 b:0007 l:00043c d:0018c0 EVAL C:/watir_testit/pop.rb:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:00043c d:00043c TOP
-- Ruby level backtrace information ----------------------------------------
C:/watir_testit/pop.rb:6:in <main>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialog
s/alert.rb:27:inok'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialog
s/alert.rb:38:in dialog'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/window.rb:
220:inmethod_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/window.rb:247:in child'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:147:inchild_window_locators'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:200:in control_hwnd'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:319:infind_hwnd'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:319:in `enum_child_windows'
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.