I am trying to implement nsurlconnectiondatadelegate as I need to support async mode - in synchronous mode redirects are followed automatically which I do not want.
For reference I have the code working in synchronous mode with urlRequest etc.
The problem is I can not get FPC/Lazarus to compile my code.
...
Code snippets
{$mode objfpc}
{$modeswitch objectivec1}
{$modeswitch objectivec2}
...
// We need to implement support for NSURLConnectionDelegate and NSURLConnectionDataDelegate
TmsMacRequestDelegate = objcclass(NSObject)
public
// this will set flag when done
procedure connectionDidFinishLoading(ANSUC: NSURLConnection); message onnectionDidFinishLoading:'; override;
// ... implement rest?
end;
...
requestDelegate := TmsMacRequestDelegate.alloc.init;
urlConnection := NSURLConnection.connectionWithRequest_delegate(urlRequest, requestDelegate);
// ... setup flag
urlConnection.start;
// ... wait here in loop checking flag set by "finish loading"
...
With the above, initial testing seems going-not-so-well. We reach urlConnection.start; but connectionDidFinishLoading never gets called. My theory is that it may be because we do not fully implement the delegate. However, doing so gives me other problems - here is declaration:
TmsMacRequestDelegate = objcclass(NSObject)
public
procedure connectionDidFinishLoading(ANSUC: NSURLConnection); message 'connectionDidFinishLoading:'; override;
procedure connection(ANSUC: NSURLConnection; didReceive: NSURLResponse); message 'connection::';
procedure connection(ANSUC: NSURLConnection; didReceive: NSData); message 'connection::';
procedure connection(ANSUC: NSURLConnection; didSendBodyData: Integer; totalBytesWritten: Integer; totalBytesExpectedToWrite: Integer); message 'connection::::';
procedure connection(ANSUC: NSURLConnection; willSend: NSURLRequest; redirectResponse: PNSURLResponse); message 'connection:::';
procedure connection(ANSUC: NSURLConnection; willCacheResponse: NSCachedURLResponse); message 'connection::';
end;
In one function I have translated NSURLResponse? as a pointer to
NSURLResponse... But not sure what is correct here?
Compiler complains that I have to add "override" on my first function (although none of the functions are implemented in NSObject?) with this message:
Error: Inherited methods can only be overridden in Objective-C and
Java, add "override" (inherited method defined in
NSURLConnectionDelegateCategory
If I add "override" like suggested I get:
Error: :219:1: error: invalid symbol redefinition
Error: "-TmsMacRequestDeletegate connection::]":
Error: ^
Sorry for the late reply. I don't actively follow SO, but someone just pointed me to this post.
The declaration of the NSURLConnectionDataDelegateProtocol is available in the CocoaAll unit that ships with FPC. You can declare your delegate as objcclass(NSObject, NSURLConnectionDataDelegateProtocol) so
you don't need to specify the message name for each method/message (the compiler will take them from the protocol/interface)
the compiler can point out any errors in terms of missing methods/clashing message names
The main issue is that your message names are incomplete. E.g. for your first "connection" method, it has to be 'connection:didReceiveResponse:'. That's why the runtime is not finding them.
Related
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.
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 Eiffel and I'm trying to create a simple class called "Monomio", I have 3 features that are attributes and a feature that's a function. The problem is that I'm getting a syntax error, I compared it to other classes I found but can't find the error here. This is my code
class
MONOMIO
create
make
feature {NONE} -- Initialization
make
-- Initialization for `Current'.
do
end;
coeficiente: INTEGER;
-- El número que será el coeficiente del monomio
exponenteX: INTEGER;
-- El exponente de la variable X
exponenteY: INTEGER;
-- El exponente de la variable Y
evaluar(valX: INTEGER; valY: INTEGER): INTEGER is
do
Result := coeficiente*(valX^expX)*(valY^expY)
end;
end
And this is the error I'm getting:
Syntax error at line 28 in class MONOMIO
evaluar(valX: INTEGER; valY: INTEGER): INTEGER is
---------------------------------------------^
do
I hope anyone can help me with this. Thanks.
I think the problem is the keyword "is". This has been deprecated, and if you are compiling with standard syntax (as you will be by default), then it is an error.
Just remove "is".
The problem of "syntax error" as an uninformative error message is one I have long been complaining about. It is entirely fixable, and no compiler should use it.
I have a function with the following signature:
static func dictionaryToJSON<K : ToJSON,V : ToJSON> ( dictionary : Dictionary<K,V>) -> JValue
You can find it here.
When I attempt to call this function, I get the error Cannot invoke 'dictionaryToJSON' with an argument list of type '(Dictionary<Domain, Account>)'. Here is the call:
let accounts : JValue = Aeson.dictionaryToJSON( self.accounts)
self.accounts has type Dictionary<Domain,Account>, and Domain and Account both implement the protocol ToJSON. Is there any reason why this doesn't type check? This is for Swift 2 (XCode 7 beta 6), so maybe there is a compiler bug?
It looks like I commented out Domain's implementation of ToJSON to debug and forgot. It's working now.
I can't call a java wrapping service in Acceleo because it doesn't recognize parameters type. This is my simple test code: the main calls a query stored in Services.mtl, that calls the java service that just return the name of an object "Send"
Main.mtl
[file ('system.P', false, 'UTF-8')]
[for (t : Send | aSystemBehavior.transitions)) ]
[getName(t)/]
[/for]
[/file]
Services.mtl
[query public getName(arg0 : Send) : String
= invoke('myPackage.Services', 'getName(myPackage.Send)', Sequence{arg0})
/]
Services.java
public class Services
{
public String getName(Send t)
{return t.getName();}
}
The Error Log shows:
Invalid result for expression
self.invoke('myPakage.Services',
'getName(myPakage.Send)', Sequence {arg0}) at line 0 in
Module services for query getName(Send). Last recorded value of self
was org.eclipse.emf.ecore.impl.DynamicEObjectImpl#1f00eb36 (eClass:
org.eclipse.emf.ecore.impl.EClassImpl#2c2aade3 (name: Send)
(instanceClassName: null) (abstract: false, interface: false)).
Problem found while generating the file system.P'.
If I use a String as parameter type instead of Send, everything works fine.
Does the package containing the service "Services" has been exported? If not, open the file MANIFEST.MF, go in the runtime tab and add its package to the list of exported packages. Are you sure that your "Send" object has a name? This message only indicates that null was returned by the query getName.
I don't have anymore this problem... I created a new Acceleo project from scratch, and it works. I am not sure what was the problem... maybe it's something about che choice of metamodels to import during the creation of the Module (I have to choose between run-tim and develop-time metamodel).