in official documentation about handleReset from useFormik i have read that is type is:
handleReset: () => void
However, rewriting working JS code to TS I received error
Expected 1 arguments, but got 0.ts(2554)
Formik.d.ts(16, 19): An argument for 'e' was not provided.
Affter clicking onto handleReset it toook me to fromik.d.ts where it stands that:
handleReset: (e: any) => void;
Blockquote
Does it mean error in documentation? Should I call it with null? I really have no idea what to pass.
Related
I am not sure of the behaviour of error messages in Substrate runtimes in relation to Substrate UI, and if they inherently cause a transaction failure or not.
For example in the democracy SRML I see the following line:
ensure!(!<Cancellations<T>>::exists(h), "cannot cancel the same proposal twice");
Which presumably is a macro that ensures that the transaction fails or stops processing if the h (the proposal hash) already exists. There is clearly a message associated with this error.
Am I right to assume that the transaction fails (without the rest of the SRML code being executed) when this test fails?
If so, how do I detect the failure in Substrate UI, and possibly see the message itself?
If not, then presumably some further code is necessary in the runtime module which explicitly creates an error. I have seen Err() - but not in conjunction with ensure!()
As https://github.com/paritytech/substrate/pull/3433 is merged, the ExtrinsicFailed event now includes a DispatchError, which will provide additional error code.
There isn't much documentations available so I will just use system module as example.
First you need to decl_error, note the error variants can only be simple C like enum
https://github.com/paritytech/substrate/blob/5420de3face1349a97eb954ae71c5b0b940c31de/srml/system/src/lib.rs#L334
decl_error! {
/// Error for the System module
pub enum Error {
BadSignature,
BlockFull,
RequireSignedOrigin,
RequireRootOrigin,
RequireNoOrigin,
}
}
Then you need to associate the declared Error type
https://github.com/paritytech/substrate/blob/5420de3face1349a97eb954ae71c5b0b940c31de/srml/system/src/lib.rs#L253
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error;
Then you can just return your Error in dispatch calls when things failed
https://github.com/paritytech/substrate/blob/5420de3face1349a97eb954ae71c5b0b940c31de/srml/system/src/lib.rs#L543
pub fn ensure_root<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<(), Error>
where OuterOrigin: Into<Result<RawOrigin<AccountId>, OuterOrigin>>
{
match o.into() {
Ok(RawOrigin::Root) => Ok(()),
_ => Err(Error::RequireRootOrigin),
}
}
Right now you will only able to see a two numbers, module index and error code from JS side. Later there could be support to include the error details in metadata so that frontend will be able to provide a better response.
Related issue:
https://github.com/paritytech/substrate/issues/2954
The ensure! macro is expaneded as:
#[macro_export]
macro_rules! fail {
( $y:expr ) => {{
return Err($y);
}}
}
#[macro_export]
macro_rules! ensure {
( $x:expr, $y:expr ) => {{
if !$x {
$crate::fail!($y);
}
}}
}
So basically, it's just a quicker way to return Err. At 1.0, the error msg will only be printed to stdout(at least what I've tested so far), doesn't know if it'll be included in blockchain in the future(so can be viewed in substrate ui)..
I'm new to Jasmine, and am getting this error:
Expected spy unknown to have been called.
What does this mean? I'm spying on a method, but am not sure what unknown means.
The answer is really simple! The spy didnt have a name, so it's called "unknown" by default.
To name it, I simply did this
var mySpy = jasmine.createSpy("JamesBond");
Then it failed with something more readable!
Expected spy JamesBond to have been called.
The "unknown" value is due to the inexistence of the name attribution for the spy.
before:
Error: Expected spy unknown.getPlans to have been called.
const mockPlansServiceEmpty: Spide<PlansService> = jasmine.createSpyObj(
['getPlans', 'separateValidFromInvalidPlans']
);
after:
Error: Expected spy mockPlansEmpty.getPlans to have been called.
const mockPlansServiceEmpty: Spide<PlansService> = jasmine.createSpyObj(
'mockPlansEmpty',
['getPlans', 'separateValidFromInvalidPlans']
);
I'm trying to render a component with reason-react after I get data from fetch but I receive a type error. This is my code:
GetData.re:
let get = () => Js.Promise.(
Fetch.fetch("localhost:8000/data.json")
|> then_(Fetch.Response.json)
|> resolve
);
Main.re:
let data = () =>
GetData.get()
|> Js.Promise.then_(result =>
Js.Promise.resolve(
ReactDOMRe.renderToElementWithId(
<ItemsList itemsList=result />,
"root"
)
)
)
And I recive this error:
29 │ let data = () =>
30 │ GetData.get()
31 │ |> Js.Promise.then_(result =>
32 │ Js.Promise.resolve(
. │ ...
37 │ )
38 │ );
This has type:
(Js.Promise.t(list(Item.item))) => Js.Promise.t(unit)
But somewhere wanted:
(Js.Promise.t(Js.Promise.t(Js.Json.t))) => 'a
The incompatible parts:
Js.Promise.t(list(Item.item)) (defined as Js.Promise.t(list(Item.item)))
vs
Js.Promise.t(Js.Promise.t(Js.Json.t)) (defined as
Js.Promise.t(Js.Promise.t(Js.Json.t)))
Further expanded:
list(Item.item)
vs
Js.Promise.t(Js.Json.t) (defined as Js.Promise.t(Js.Json.t))
ninja: build stopped: subcommand failed.
I also try to replace render with simple Js.log(result) and it works, I try to check type of Js.log and render (passing their invocation to a function which takes an int and watching the error) and they are both unit
Where is my mistake? and is there something like toplevel/utop for Reason? It actually helps a lot in OCaml
You have several issues in your code:
Fetch.Response.json returns a Js.Json.t (wrapped in a promise), indicating the structure of the data is unknown to the type system and needs to be decoded. You can do that using bs-json for example.
Js.Promise.resolve takes any value and wraps that value in a Js.Promise.t. But since Js.Promise.then_ already returns a promise, you now have a promise wrapped in a promise. You should therefore just remove |> resolve from your get function.
The type error tells you about both of these issues (list(Item.item) vs Js.Promise.t(Js.Json.t) (defined as Js.Promise.t(Js.Json.t))), but it doesn't tell you where it "went wrong". To narrow down type errors like this you can annotate the type of you functions and let-bindings. For example, if you had annotated get:
let get : Js.Promise.t(list(Item.item))) = ...
It would have shown you that the problem is within the get function.
Rule of thumb: Don't assume, annotate.
Edit: To answer the toplevel/repl question: There is a toplevel for Reason called rtop, but it does not work with BuckleScript and JavaScript APIs. There is also the Reason playground which does work with BuckleScript and JS APIs, but is not able to load external libraries.
I am just trying to plant AJAX Chat for my website users. I have successfully completed the installation process with database configuration. But when I am trying to brows the domain.com/ajaxchat/index.php its returning this error given below:
XML Parsing Error: junk after document element Location: http://futurenext.esy.es/inc/chat/ Line Number 2, Column 1:
I think that the problem is in AJAXChatTemplate.php , and here the code is:
function getContent() {
if(!$this->_content) {
$this->_content = AJAXChatFileSystem::getFileContents($this->_templateFile);
}
return $this->_content;
And the error message is like:
" Non-static method AJAXChatFileSystem::getFileContents() should not be called statically, assuming $this from incompatible context in line 37"
Now please any one can help me to fix the problem. What is the problem here I can't really understand. Thanks.
I'm totally confused about adding mongo data to template data. I haven't even started trying to get the data from a database as I can't get my templates to see test data (see below). This is in docpad.coffee for the moment, but ultimately g will be the output of mongoDB.
events:
extendTemplateData: (opts) ->
# {templateData} = opts
getGigsData: ->
g = { "date" : "3-4-2013", "location" : "Gent" }
return g
opts.templateData["getGigsData"] = getGigsData
And I hope to access it with <%= #getGigsData().date %>
Thanks so much for some guidance
I should add that this design is based on wanting to make it easy for the band to add gigs, without letting them edit the page content itself as I fear they would mess up the markup - if there are other ways to achieve this goal, I'd be pleased to hear.
Tried this locally. And hit the issue:
debug: Emitting the event: extendTemplateData
→ [2014-02-14 01:38:50.030] [/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/out/lib/docpad.js:1184] [DocPad.emitSerial]
error: Something went wrong with the action
→ [2014-02-14 01:38:50.037] [/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/out/lib/interfaces/console.js:107] [ConsoleInterface.destroyWithError]
error: An error occured:
ReferenceError: getGigsData is not defined
at Object.docpadConfig.events.extendTemplateData (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/docpad.coffee:42:44)
at ambi (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:25:27)
at DocPad.<anonymous> (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/out/lib/docpad.js:995:25)
at ambi (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:23:18)
at Task.<anonymous> (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:45:23)
at ambi (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:23:18)
at fire (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:163:25)
at b (domain.js:183:18)
at Domain.run (domain.js:123:23)
at Task.fire (/Users/balupton/Projects/docpad-extras/skeletons/so-21747504/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:173:25)
at processImmediate [as _immediateCallback] (timers.js:330:15)
Which indicates that the error is actually inside our event handler, rather than inside our code. That for some reason getGigsData is not being set, despite our:
getGigsData: ->
g = { "date" : "3-4-2013", "location" : "Gent" }
return g
Examining the code, as a CoffeeScript user, I found the issue. As a non-coffeescript user, you can use the coffeescript compiler on the coffeescript website http://coffeescript.org to see the compiled javascript, which is:
({
events: {
extendTemplateData: function(opts) {
({
getGigsData: function() {
var g;
g = {
"date": "3-4-2013",
"location": "Gent"
};
return g;
}
});
return opts.templateData["getGigsData"] = getGigsData;
}
}
});
As we can see that is definitely not what we expected. We are just defining getGigsData inside an object, then doing nothing with it.
The issue is that we used a colon instead of an equals sign, so getGigsData: -> instead of getGigsData = ->. This is not a coffeescript thing, but you would have run into the same issue if this was javascript too, albeit javascript may be a bit more obvious due to the necessary squiggly braces around object definitions.
As a sidenote, if you prefer to use JavaScript with DocPad for whatever reason, that is totally supported. You could use a docpad.json or docpad.js file for your docpad configuration file. Another option, is to continue using CoffeeScript then just wrap JavaScript code within the backtick, see: http://coffeescript.org/#embedded