Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

If a parameter is not specified in a Rug DSL BDD test for a Rug TypeScript editor, an error message should be shown not a stacktrace #224

Closed
russmiles opened this issue Jan 26, 2017 · 4 comments

Comments

@russmiles
Copy link
Contributor

If I have an editor that looks like the following:

import { ProjectEditor } from "@atomist/rug/operations/ProjectEditor"
import { Status, Result, Parameter } from "@atomist/rug/operations/RugOperation"
import { Project, Pair, File } from '@atomist/rug/model/Core'
import { PathExpression, PathExpressionEngine, TreeNode, Match } from '@atomist/rug/tree/PathExpression'


let params: Parameter[] = [
    {
        name: "description",
        displayName: "Description",
        description: "Text to be added to the README.md",
        validInput: "Any valid text",
        minLength: 1,
        pattern: "@any",
    }
]

interface Parameters {
    description: string
}

export let editor: ProjectEditor = {
    tags: ["simple"],
    name: "SimpleSampleEditor",
    description: "A simple sample TypeScript editor",
    parameters: params,
    edit(project: Project, p: Parameters): Result {

        project.addFile("README.md", p.description);

        return new Result(Status.Success, "README.md added to project")
    }
}

And a test such as the following:

scenario SimpleSampleEditor should just add a file called "README.md" to the target project

given
  Empty

when
  SimpleSampleEditor

then
  fileExists "README.md"
    and fileContains "README.md" "Hello, Rug TypeScript World!"

Then I get a stacktrace such as the following when rug test is executed using rug-cli version 0.21.3:

$ rug test -X
Resolving dependencies for russmiles:scattered-rugs:0.1.0 ← local completed
Loading russmiles:scattered-rugs:0.1.0 ← local into runtime completed
Executing scenario SimpleSampleEditor should just add a file called "README.md" to the target project...      
Running test scenarios in russmiles:scattered-rugs:0.1.0 ← local failed

java.lang.NullPointerException
	at com.atomist.rug.kind.core.ProjectMutableView.addFile(ProjectMutableView.scala:212)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.atomist.rug.spi.TypeOperation.invoke(TypeInformation.scala:88)
	at com.atomist.rug.runtime.js.interop.SafeCommittingProxy$MethodInvocationProxy.call(SafeCommittingProxy.scala:75)
	at com.atomist.rug.runtime.js.interop.SafeCommittingProxy$MethodInvocationProxy.call(SafeCommittingProxy.scala:58)
	at jdk.nashorn.internal.scripts.Script$Recompilation$91$566AA$\^eval\_$cu1$restOf.L:1$edit(<eval>:19)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:641)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
	at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
	at com.atomist.rug.runtime.js.JavaScriptInvokingProjectOperation.invokeMemberWithParameters(JavaScriptInvokingProjectOperation.scala:77)
	at com.atomist.rug.runtime.js.JavaScriptInvokingProjectEditor$$anonfun$1.apply(JavaScriptInvokingProjectEditor.scala:38)
	at com.atomist.rug.runtime.js.JavaScriptInvokingProjectEditor$$anonfun$1.apply(JavaScriptInvokingProjectEditor.scala:30)
	at com.atomist.util.Timing$.time(Timing.scala:16)
	at com.atomist.rug.runtime.js.JavaScriptInvokingProjectEditor.modifyInternal(JavaScriptInvokingProjectEditor.scala:30)
	at com.atomist.project.edit.ProjectEditorSupport$class.modify(ProjectEditorSupport.scala:39)
	at com.atomist.rug.runtime.js.JavaScriptInvokingProjectEditor.modify(JavaScriptInvokingProjectEditor.scala:15)
	at com.atomist.rug.loader.DecoratingOperationsLoader$DecoratedProjectEditor.modify(DecoratingOperationsLoader.java:275)
	at com.atomist.rug.test.TestRunner.com$atomist$rug$test$TestRunner$$executeAgainst(TestRunner.scala:108)
	at com.atomist.rug.test.TestRunner$$anonfun$1.apply(TestRunner.scala:75)
	at com.atomist.rug.test.TestRunner$$anonfun$1.apply(TestRunner.scala:68)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.AbstractTraversable.map(Traversable.scala:104)
	at com.atomist.rug.test.TestRunner.run(TestRunner.scala:68)
	at com.atomist.rug.cli.command.test.TestCommand.lambda$runTests$7(TestCommand.java:142)
	at com.atomist.rug.cli.output.ProgressReportingOperationRunner.run(ProgressReportingOperationRunner.java:20)
	at com.atomist.rug.cli.command.test.TestCommand.runTests(TestCommand.java:139)
	at com.atomist.rug.cli.command.test.TestCommand.run(TestCommand.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.atomist.rug.cli.command.AbstractAnnotationBasedCommand.invokeCommandMethod(AbstractAnnotationBasedCommand.java:60)
	at com.atomist.rug.cli.command.AbstractAnnotationBasedCommand.run(AbstractAnnotationBasedCommand.java:48)
	at com.atomist.rug.cli.command.AbstractCompilingAndOperationLoadingCommand.run(AbstractCompilingAndOperationLoadingCommand.java:59)
	at com.atomist.rug.cli.command.AbstractCommand.run(AbstractCommand.java:44)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.atomist.rug.cli.command.ReflectiveCommandRunMethodRunner.invokeCommand(ReflectiveCommandRunMethodRunner.java:20)
	at com.atomist.rug.cli.command.ReflectiveCommandRunner.runCommand(ReflectiveCommandRunner.java:71)
	at com.atomist.rug.cli.Runner.runCommand(Runner.java:121)
	at com.atomist.rug.cli.Runner.run(Runner.java:44)
	at com.atomist.rug.cli.Main.main(Main.java:17)

Instead an error would be preferable?

@kipz
Copy link
Contributor

kipz commented Feb 9, 2017

Great bug report!

@kipz
Copy link
Contributor

kipz commented Feb 9, 2017

The reason for this is that your parameter is being treated as optional/required=false, so validation is passing.

@kipz
Copy link
Contributor

kipz commented Feb 9, 2017

I believe required=true should be the default.

@kipz kipz added this to the 0.12.0 milestone Feb 9, 2017
kipz added a commit that referenced this issue Feb 9, 2017
kipz added a commit that referenced this issue Feb 9, 2017
kipz added a commit that referenced this issue Feb 9, 2017
kipz added a commit that referenced this issue Feb 9, 2017
@kipz
Copy link
Contributor

kipz commented Feb 9, 2017

Available in 0.12.0

@kipz kipz closed this as completed Feb 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants