Why does the error method return an error? - xtext

I want to validate input corresponding to the following grammar snippet:
Declaration:
name = ID "=" brCon=BracketContent
;
BracketContent:
decCon=DecContent (comp+=COMPARATOR content+=DecContent)*
;
DecContent:
(neg=("!"|"not"))? singleContent=VarContent (op+=OPERATOR nextCon+=VarContent)*
;
My validation looks like that:
#Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.decCon.singleContent.reference == null) {
return
}
var names = newArrayList
var con = dec.decCon.singleContent
while(con.reference != null) {
con = getThatReference(con).singleContent
if(names.contains(getParentName(con))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.bracketContent_DecCon,
CYCLE_IN_HIERARCHY)
return
}
names.add(getParentName(con))
}
}
But when I test this validation with a testCaseit returns me an error message:
Expected ERROR 'raven.sqf.CycleInHierarchy' on Declaration at [-1:-1] but got
ERROR (org.eclipse.emf.ecore.impl.EClassImpl#5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
ERROR (org.eclipse.emf.ecore.impl.EClassImpl#5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
I just can't figure out what's wrong with it so I hope that someone of you might have an idea.
Greetings Krzmbrzl

You test utility tells you that the validator did not produce the expected validation error ("CycleInHierarchy").
Instead, the validator produced the error "Error executing EValidator".
Which means an exception has been thrown when your validator was executed.

It turned out it was an internal error...I'm still not exactly sure what went wrong but I have rewritten my validation method and now it works as expected.
Now the method looks like this:
enter code here#Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.varContent.reference == null) {
//proceed only if there is a reference
return
}
var content = dec.varContent
var names = newArrayList
while(content.reference != null && !names.contains(getParentName(content))) {
names.add(getParentName(content))
content = content.reference.varContent
if(names.contains(getParentName(content))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.declaration_BrCon,
CYCLE_IN_HIERARCHY)
return
}
}
}
I have the suspicion that there was a problem with the usage of my "getThatReference" in this case.
Greeting Krzmbrzl

Related

Google Sheets Script Error - Cannot read property '1' of null (line 7)

I'm using the following script to pull data from bulk json files:
function importRegex(url, regexInput) {
var output = '';
var fetchedUrl = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
if (fetchedUrl) {
var html = fetchedUrl.getContentText();
if (html.length && regexInput.length) {
output = html.match(new RegExp(regexInput, 'i'))[1];
}
}
// Grace period to not overload
Utilities.sleep(1000);
return output;
}
Then this formula with the desired URL in E3:
=IMPORTREGEX(E3,"(.*')")
It worked completely fine to begin with, now I'm suddenly getting the error, seemingly without making any changes, any tips?
This error is because of lacking a null check.
You are now using the return value of html.match() whether it is null or not.
So you should check if the return value is null and if it has enough length.
Like this:
if (html.length && regexInput.length) {
let match = html.match(new RegExp(regexInput, 'i'));
if ( match != null && match.length > 1 ){
output = match[1];
}
}

typo3 flow: catch exception and forward back to originating action

In my typo3 flow app I want to stop execution after throwing an exception as flash-message. Therefore I wrote this:
public function updateAction(Mitglied $mitglied) {
if ($xy == 'z') {
try {
throw new \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException('Fehler: In dieser Kombination nicht zulässig', 1);
} catch (\TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException $e) {
$this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error($e->getMessage()));
}
}
$this->mitgliedRepository->update($mitglied);
$this->addFlashMessage('Mitglied erfolgreich geändert.');
$this->redirect('index');
}
The message ist shown, as I wanted, as flash-message. But the execution of the function doesn't stop. Does anybody know, why and how to prevent? A redirect to the originating action would be desired for the case, that the if-condition is true.
I got it now with the following code:
// get back to originating request - see https://git.typo3.org/Packages/TYPO3.Flow.git/blob/master:/Classes/TYPO3/Flow/Mvc/Controller/ActionController.php
$referringRequest = $this->request->getReferringRequest();
if ($referringRequest === NULL) {
return;
}
$packageKey = $referringRequest->getControllerPackageKey();
$subpackageKey = $referringRequest->getControllerSubpackageKey();
if ($subpackageKey !== NULL) {
$packageKey .= '\\' . $subpackageKey;
}
$argumentsForNextController = $referringRequest->getArguments();
$argumentsForNextController['__submittedArguments'] = $this->request->getArguments();
$argumentsForNextController['__submittedArgumentValidationResults'] = $this->arguments->getValidationResults();
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $packageKey, $argumentsForNextController);
In the end this is much easier:
$this->errorAction()->forwardToReferringRequest();

FromOutcome for `Switch Node` directing flow to `Method Call Node` don't wont to work

I have difined my flow as:
builder.id("", PublisherBean.PUBLISHER_FLOW_NAME);
builder.viewNode("list", "/pages/publishers.xhtml");
builder.viewNode("details", "/pages/publishers-details.xhtml");
builder.viewNode("deleted", "/pages/publishers-deleted.xhtml");
builder.viewNode("form", "/pages/publishers-form.xhtml");
builder.viewNode("exit", "/index.xhtml");
builder.methodCallNode("invoke-update")
.expression("#{publisherBean.update()}")
.defaultOutcome("details");
builder.methodCallNode("switch-fail")
.defaultOutcome("invoke-publishers")
.expression("#{publisherBean.switchFail()}");
builder.switchNode("proceed-action-request")
.defaultOutcome("switch-fail")
.switchCase()
.condition("#{publisherBean.actionType.ifEdit()}").fromOutcome("form");
builder.switchNode("go-for-it")
.defaultOutcome("switch-fail")
.switchCase()
.switchCase()
.condition("#{publisherBean.actionType.ifEdit()}").fromOutcome("invoke-update");
as you can see, there is two switch nodes. First directs to a View Node, second one is trying to direct to a Method Call Node.
First one works fine, however second is giving me a headache. Second one is giving me an error
Unable to find matching navigation case with from-view-id '/pages/publishers-form.xhtml' for action '#{publisherBean.proceed()}' with outcome 'proceed-form'.
proceed function is just
public String proceed() {
LOG.log(Level.OFF, "Form proceed in action type {0}", actionType);
return "go-for-it";
}
Logged info confirms, that publisherBean.actionType.ifEdit() returns true, however that fact is ignored. If i change outcome from invoke-update to form or any other View Node id, then it "works fine".
Is it i'm doing something wrong, or Method Call Node cant be used as an outcome to a Switch Node?
I run into this issue too. In my case the problem is in calling Method Call Node after another Method Call Node.
I invesigated it a bit and found a problem in: com.sun.faces.application.NavigationHandlerImpl.synthesizeCaseStruct method. This method is used to determine where to go from methodCallNode or switchCallNode and it only looks at viewNodes and returnNodes.
private CaseStruct synthesizeCaseStruct(FacesContext context, Flow flow, String fromAction, String outcome) {
CaseStruct result = null;
FlowNode node = flow.getNode(outcome);
if (null != node) {
if (node instanceof ViewNode) {
result = new CaseStruct();
result.viewId = ((ViewNode)node).getVdlDocumentId();
result.navCase = new MutableNavigationCase(fromAction,
fromAction, outcome, null, result.viewId,
flow.getDefiningDocumentId(), null, false, false);
} else if (node instanceof ReturnNode) {
String fromOutcome = ((ReturnNode)node).getFromOutcome(context);
FlowHandler flowHandler = context.getApplication().getFlowHandler();
try {
flowHandler.pushReturnMode(context);
result = getViewId(context, fromAction, fromOutcome, FlowHandler.NULL_FLOW);
// We are in a return node, but no result can be found from that
// node. Show the last displayed viewId from the preceding flow.
if (null == result) {
Flow precedingFlow = flowHandler.getCurrentFlow(context);
if (null != precedingFlow) {
String toViewId = flowHandler.getLastDisplayedViewId(context);
if (null != toViewId) {
result = new CaseStruct();
result.viewId = toViewId;
result.navCase = new MutableNavigationCase(context.getViewRoot().getViewId(),
fromAction,
outcome,
null,
toViewId,
FlowHandler.NULL_FLOW,
null,
false,
false);
}
}
} else {
result.newFlow = FlowImpl.SYNTHESIZED_RETURN_CASE_FLOW;
}
}
finally {
flowHandler.popReturnMode(context);
}
}
} else {
// See if there is an implicit match within this flow, using outcome
// to derive a view id within this flow.
String currentViewId = outcome;
// If the viewIdToTest needs an extension, take one from the currentViewId.
String currentExtension;
int idx = currentViewId.lastIndexOf('.');
if (idx != -1) {
currentExtension = currentViewId.substring(idx);
} else {
// PENDING, don't hard code XHTML here, look it up from configuration
currentExtension = ".xhtml";
}
String viewIdToTest = "/" + flow.getId() + "/" + outcome + currentExtension;
ViewHandler viewHandler = Util.getViewHandler(context);
viewIdToTest = viewHandler.deriveViewId(context, viewIdToTest);
if (null != viewIdToTest) {
result = new CaseStruct();
result.viewId = viewIdToTest;
result.navCase = new MutableNavigationCase(fromAction,
fromAction, outcome, null, result.viewId,
null, false, false);
}
}
return result;
}

AS3 Workers : Received Object throwing " Type Coercion failed" error

I have created a worker class to Parse a Collada file(Alternativa3d Engine).
I am sending dae/xml file to Worker class and parsing it. While receiving it at Main class, got an error saying "Type Coercion failed".
Here is the code.
Main Class: Sending Data
if (bgWorkerX.state == WorkerState.RUNNING)
{
var _b:ByteArray = (new modelX() as ByteArray);
var xml:XML = (new XML(_b.readUTFBytes(_b.length)));
bgWorkerCCX.send(["START_PARSING", XParser]);
}
Main Class : Receiving Data
if (!resultCX.messageAvailable)
{
return;
}
var result:String = resultCX.receive(true);
if (result == "SUCCESS")
{
var txt3:TextField = new TextField();
txt3.text = "Parsed result : " + Mesh(resultCX.receive(true)); //ERROR LINE : TYPE COERCION FAILED.
}
}
Worker Class :
private function handleCommandMessage(event:Event):void
{
if (!commandChannel.messageAvailable) {
return;
}
var message:Array = commandChannel.receive() as Array;
if (message != null && message[0] == "START_PARSING")
{
StartParsing(XML(message[1]));
}
}
private function StartParsing(xml:XML):void
{
parser = new ParserCollada();
parser.parse(xml);
resultChannel.send("SUCCESS");
resultChannel.send(parser.getObjectByName('mainbody') as Mesh);
}
Anybody has idea how to convert similar kind of objects to desired type?
Try to use ByteArray.writeObject...
ByteArray.readObject methods for that...
I also faced this issue but not sure if is possible to do.
Let me know please if you succeed to solve it.

Grails save() failure; can't figure out why

I am having a problem saving a Domain object. Below is my Controller code:
def onContactRequest = {
if(request.method == 'POST') {
if(User.findByUserTelephone(params.userTelephone)) {
User thisUser = User.findByUserTelephone(params.userTelephone)
Contact thisContact = new Contact()
thisContact.setContact(thisUser)
println("This Contact: " + thisContact.getContact());
thisContact.setBelongsTo(request.user)
println("This User: " + request.user)
if(thisContact.save(flush: true)) {
render(thisContact.belongsTo.userName + " just requested " + thisContact.getContact().userName )
} else {
render("There was a problem saving the Contact.")
if( !thisContact.save() ) {
thisContact.errors.each {
println it
}
}
}
} else {
User thisUser = new User()
thisUser.setUserName("Not Set")
thisUser.setUserTelephone(params.userTelephone)
thisUser.save()
Contact thisContact = new Contact()
thisContact.setContact(thisUser)
thisContact.setBelongsTo(request.user)
if(thisContact.save(flush: true)) {
render(thisContact.belongsTo.userName + " just requested " + thisContact.getContact().userName )
} else {
render("There was a problem saving the Contact.")
if( !thisContact.save() ) {
thisContact.errors.each {
println it + "\n"
}
}
}
}
} else {
}
The error message is printed with the following code; hence it's very ugly:
if( !thisContact.save() ) {
thisContact.errors.each {
println it + "\n"
}
}
From what I can tell, it's complaining that either the Contact or User instance is null; however that can't be true (look below)
This Contact: org.icc.callrz.User.User : 2
This User: org.icc.callrz.User.User : 1
Field 'user' in org.icc.callrz.Contact.Contact is:
static belongsTo = [
user: User
]
Error detail below:
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'org.icc.callrz.Contact.Contact' on field 'user': rejected value [null]; codes [org.icc.callrz.Contact.Contact.user.nullable.error.org.icc.callrz.Contact.Contact.user,org.icc.callrz.Contact.Contact.user.nullable.error.user,org.icc.callrz.Contact.Contact.user.nullable.error.org.icc.callrz.User.User,org.icc.callrz.Contact.Contact.user.nullable.error,contact.user.nullable.error.org.icc.callrz.Contact.Contact.user,contact.user.nullable.error.user,contact.user.nullable.error.org.icc.callrz.User.User,contact.user.nullable.error,org.icc.callrz.Contact.Contact.user.nullable.org.icc.callrz.Contact.Contact.user,org.icc.callrz.Contact.Contact.user.nullable.user,org.icc.callrz.Contact.Contact.user.nullable.org.icc.callrz.User.User,org.icc.callrz.Contact.Contact.user.nullable,contact.user.nullable.org.icc.callrz.Contact.Contact.user,contact.user.nullable.user,contact.user.nullable.org.icc.callrz.User.User,contact.user.nullable,nullable.org.icc.callrz.Contact.Contact.user,nullable.user,nullable.org.icc.callrz.User.User,nullable]; arguments [user,class org.icc.callrz.Contact.Contact]; default message [Property [{0}] of class [{1}] cannot be null]
Edit: I have no problem creating Contact domain objects using the 'generate-all' code.
SOLUTION: I had a look at the code in the view, and it looked like to create the ID was used, so I changed the code to:
thisContact.user.id = request.user.id
However, then I got an error: java.lang.NullPointerException: Cannot set property 'id' on null object but the output of println request.user was not blank so I wasn't sure why that was appearing.
I then changed the offending line to:
thisContact.user = request.user
Now everything is working. :)
Try replacing:
thisContact.setBelongsTo(request.user)
With:
thisContact.user = thisUser
The syntax you are using is wrong as far as I know, not to mention that you construct thisUser and then go on to use request.user instead.

Resources