Error: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer and local server is down and app crashed - mongodb-query

C:\project\server-assign-11\node_modules\bson\lib\error.js:41
var _this = _super.call(this, message) || this;
^
BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
at new BSONTypeError (C:\project\server-assign-11\node_modules\bson\lib\error.js:41:28)
at new ObjectId (C:\project\server-assign-11\node_modules\bson\lib\objectid.js:66:23)
at ObjectId (C:\project\server-assign-11\node_modules\bson\lib\objectid.js:26:20)
at C:\project\server-assign-11\index.js:58:26
at Layer.handle [as handle_request] (C:\project\server-assign-11\node_modules\express\lib\router\layer.js:95:5)
at next (C:\project\server-assign-11\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\project\server-assign-11\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\project\server-assign-11\node_modules\express\lib\router\layer.js:95:5)
at C:\project\server-assign-11\node_modules\express\lib\router\index.js:284:15
at param (C:\project\server-assign-11\node_modules\express\lib\router\index.js:365:14)

Related

How do I input the parameter with bytes4 type in Remix?

I created a simple contract as blow shows. When I deployed it and try to call get function, I found that I couldn't input the correct parameter with bytes4 type. No matter I used 0x01,11,"11"..., it always told that error encoding argument like this.
transact to Test.get errored: Error encoding arguments: Error: invalid arrayify value (argument="value" value="11" code=INVALID_ARGUMENT version=bytes/5.5.0)
transact to Test.get errored: Error encoding arguments: Error: invalid arrayify value (argument="value" value="0x6162" code=INVALID_ARGUMENT version=bytes/5.5.0)
What should I do ?
pragma solidity ^0.4.0;
contract Test {
mapping (bytes8 => string) public map;
function setMapping() public {
map["k1"] = "yes";
}
function get(bytes4 a) public {
}
}
You can enter the bytes in the hex form, undivided. Since bytes4 is a fixed-length array of four bytes, you always need to input exactly 4 bytes (8 hex characters).
0x12345678
12 is the first byte
34 is the second byte
etc...
Note: If you want to input empty bytes, you can use 00 in the location of the empty byte. Example: 0x00340078 (1st and 3rd byte are empty).

NumberFormatException in converting string to byte

I am trying to get the MD5 format of string
Code:
fun getEncodedData(data: String): String? {
val MD5 = "MD5"
// Create MD5 Hash
val digest = java.security.MessageDigest
.getInstance(MD5)
digest.update(data.toByte())
val messageDigest = digest.digest()
// Create Hex String
val hexString = StringBuilder()
for (aMessageDigest in messageDigest) {
var h = Integer.toHexString(0xFF and aMessageDigest.toInt())
while (h.length < 2)
h = "0$h"
hexString.append(h)
}
return hexString.toString()
}
There is a crash at: digest.update(data.toByte()). I get number format Exception
Input I am passing for data: oEXm43
There is no crash if I pass ex: 11 as a string for input data
Should the input always should be integer in the string or can it be a mixture of number and characters.
You're trying to call the update method that takes a single byte parameter, and using toByte which converts the entire string's numerical value to a single byte. This conversion method is what fails on non-numerical values inside a String.
Instead, you can use the variant of update with a byte[] parameter, and convert your String to an array of bytes (one per character) with toByteArray:
digest.update(data.toByteArray())

Flow upgrade to 0.64 results in bunch of new errors

I recently upgraded flow-bin and .flowconfig from 0.53 to 0.64 and now flow is resulting in bunch of new errors inside react-native framework files.
What can I do about this situation?
Error: node_modules/react-native/Libraries/Components/ScrollResponder.js:480
480: var { animated, ...rect } = rect;
^^^^^^^ rect. This type is incompatible with
472: rect: { x: number, y: number, width: number, height: number, animated?: boolean },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object type
Property `animated` is incompatible:
472: rect: { x: number, y: number, width: number, height: number, animated?: boolean },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ property `animated`. Property not found in
480: var { animated, ...rect } = rect;
^^^^^^^ rect
Error: node_modules/react-native/Libraries/Inspector/Inspector.js:104
104: clearTimeout(_hideWait);
^^^^^^^^^ null. This type is incompatible with the expected param type of
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Interaction/InteractionManager.js:171
171: _nextUpdateHandle = setTimeout(_processUpdate, 0 + DEBUG_DELAY);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TimeoutID. This type is incompatible with
182: _nextUpdateHandle = 0;
^ number
Error: node_modules/react-native/Libraries/Lists/FlatList.js:465
v--------------------------------
465: this._virtualizedListPairs.push({
466: viewabilityConfig: this.props.viewabilityConfig,
467: onViewableItemsChanged: this._createOnViewableItemsChanged(
...:
470: });
-^ rest parameter array of call of method `push`. Has some incompatible type argument with
249: push(...items: Array<T>): number;
^^^^^^^^ array type. See lib: /tmp/flow/flowlib_213409a3/core.js:249
Type argument `T` is incompatible:
v
465: this._virtualizedListPairs.push({
466: viewabilityConfig: this.props.viewabilityConfig,
467: onViewableItemsChanged: this._createOnViewableItemsChanged(
...:
470: });
^ object literal. This type is incompatible with
476: _virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ViewabilityConfigCallbackPair
Property `viewabilityConfig` is incompatible:
466: viewabilityConfig: this.props.viewabilityConfig,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. Inexact type is incompatible with exact type
26: viewabilityConfig: ViewabilityConfig,
^^^^^^^^^^^^^^^^^ ViewabilityConfig. See: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:26
Error: node_modules/react-native/Libraries/Lists/FlatList.js:558
558: return keyExtractor(items, index);
^^^^^ array type. This type is incompatible with the expected param type of
151: keyExtractor: (item: ItemT, index: number) => string,
^^^^^ ItemT
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:91
91: this._timers.forEach(clearTimeout);
^^^^^^^^^^^^ function type. This type is incompatible with the expected param type of
572: forEach(callbackfn: (value: T, index: T, set: Set<T>) => mixed, thisArg?: any): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: /tmp/flow/flowlib_213409a3/core.js:572
The first parameter is incompatible:
77: _timers: Set<number> = new Set();
^^^^^^ number. This type is incompatible with
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:200
200: this._timers.delete(handle);
^^^^^^ TimeoutID. This type is incompatible with the expected param type of
77: _timers: Set<number> = new Set();
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:207
207: this._timers.add(handle);
^^^^^^ TimeoutID. This type is incompatible with the expected param type of
77: _timers: Set<number> = new Set();
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:484
v
484: this.scrollToIndex({
485: animated: false,
486: index: this.props.initialScrollIndex,
487: }),
^ object literal. This type is incompatible with the expected param type of
v
266: scrollToIndex(params: {
267: animated?: ?boolean,
268: index: number,
...:
271: }) {
^ object type
Property `index` is incompatible:
486: index: this.props.initialScrollIndex,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null or undefined. This type is incompatible with
268: index: number,
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:484
v
484: this.scrollToIndex({
485: animated: false,
486: index: this.props.initialScrollIndex,
487: }),
^ object literal. This type is incompatible with the expected param type of
v
266: scrollToIndex(params: {
267: animated?: ?boolean,
268: index: number,
...:
271: }) {
^ object type
Property `index` is incompatible:
486: index: this.props.initialScrollIndex,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with
268: index: number,
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:500
500: clearTimeout(this._initialScrollIndexTimeout);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ number. This type is incompatible with the expected param type of
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1016
1016: distanceFromEnd < onEndReachedThreshold * visibleLength &&
^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1016
1016: distanceFromEnd < onEndReachedThreshold * visibleLength &&
^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1094
1094: this.props.onEndReachedThreshold * visibleLength / 2;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1094
1094: this.props.onEndReachedThreshold * visibleLength / 2;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1170
1170: distanceFromEnd < onEndReachedThreshold * visibleLength
^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1170
1170: distanceFromEnd < onEndReachedThreshold * visibleLength
^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1247
1247: return frame;
^^^^^ object type. This type is incompatible with the expected return type of
v
1210: ): ?{
1211: length: number,
1212: offset: number,
...:
1215: } => {
^ object type
Property `inLayout` is incompatible:
v
1210: ): ?{
1211: length: number,
1212: offset: number,
...:
1215: } => {
^ property `inLayout`. Property not found in
1247: return frame;
^^^^^ object type
Error: node_modules/react-native/Libraries/Lists/VirtualizedSectionList.js:236
236: key: keyExtractor(viewable.item, info.index),
^^^^^^^^^^ null or undefined. This type is incompatible with the expected param type of
101: keyExtractor: (item: Item, index: number) => string,
^^^^^^ number
Error: node_modules/react-native/Libraries/StyleSheet/flattenStyle.js:36
36: return getStyle(style);
^^^^^^^^^^^^^^^ number. This type is incompatible with the expected return type of
29: function flattenStyle(style: ?StyleObj): ?Object {
^^^^^^ object type
Found 30 errors
error Command failed with exit code 2.

warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’

I followed some similar posts to modify the code, however the warnings are still generated.
$ g++ ncfile.c -o ncfile -g -lnetcdf
ncfile.c: In function ‘int main(int, char**)’:
ncfile.c:363: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:363: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:364: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:364: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
In that block around line 363 and 364:
for(i = 0; i < ndimsp; i++) {
char * temp_name;
size_t temp_len;
temp_name = (char *)malloc(sizeof(char) * 20);
nc_inq_dim(cid, dimids[i], temp_name, &temp_len);
dimlens[i] = temp_len;
if(dimids[i] == unlimdimidp) printf("\t\t%d %s \tlength: %d (UNLIMITED)\n", i, temp_name, temp_len);
else printf("\t\t%d %s \tlength: %d\n", i, temp_name, temp_len);
total_records *= temp_len;
free(temp_name);
}
What should I get rid of the warnings. It that harmful to the results?
Thanks,
Michael
Try using the z modifier. Basically %zu for the size_t value.
this will be the outcome:
printf("\t\t%d %s \tlength: %zu\n", i, temp_name, temp_len);
Take a look at this question:
How can one print a size_t variable portably using the printf family?

Doubts regarding Compiler Construction (Flex/Bison)

Am trying to construct a simple compiler in my class, its second week and am totally stuck at these points: Am providing my simple.l as (flex and bison files are snipped to save space):
..snip..
end {return(END);}
skip {return(SKIP);}
in {return(IN);}
integer {return(INTEGER);}
let {return(LET);}
..snip..
[ \t\n\r]+
and simple.y as :
%start program
%token LET IN END
%token SKIP IF THEN ELSE WHILE DO READ WRITE FI ASSGNOP
%token NUMBER PERIOD COMMA SEMICOLON INTEGER
%token IDENTIFIER EWHILE LT
%left '-' '+'
%left '*' '/'
%right '^'
%%
program : LET declarations IN commands END SEMICOLON
declarations :
|INTEGER id_seq IDENTIFIER PERIOD
;
id_seq:
|id_seq IDENTIFIER COMMA
;
commands :
| commands command SEMICOLON
;
command : SKIP
;
exp : NUMBER
| IDENTIFIER
| '('exp')'
;
..snip..
%%
My first problem is when I compile and execute this, it properly accepts my input till the end but it does not stop at end; i.e it again comes to start state , isn't it supposed to terminate when it encounters an end :
On the input :
let
integer x.
in
skip;
end;
here is an output :
Starting parse
Entering state 0
Reading a token: let
Next token is token LET ()
Shifting token LET ()
Entering state 1
Reading a token: integer x.
Next token is token INTEGER ()
Shifting token INTEGER ()
Entering state 3
Reducing stack by rule 4 (line 22):
-> $$ = nterm id_seq ()
Stack now 0 1 3
Entering state 6
Reading a token: Next token is token IDENTIFIER ()
Shifting token IDENTIFIER ()
Entering state 8
Reading a token: Next token is token PERIOD ()
Shifting token PERIOD ()
Entering state 10
Reducing stack by rule 3 (line 20):
$1 = token INTEGER ()
$2 = nterm id_seq ()
$3 = token IDENTIFIER ()
$4 = token PERIOD ()
-> $$ = nterm declarations ()
Stack now 0 1
Entering state 4
Reading a token: in
Next token is token IN ()
Shifting token IN ()
Entering state 7
Reducing stack by rule 6 (line 25):
-> $$ = nterm commands ()
Stack now 0 1 4 7
Entering state 9
Reading a token: skip;
Next token is token SKIP ()
Shifting token SKIP ()
Entering state 13
Reducing stack by rule 8 (line 28):
$1 = token SKIP ()
-> $$ = nterm command ()
Stack now 0 1 4 7 9
Entering state 19
Reading a token: Next token is token SEMICOLON ()
Shifting token SEMICOLON ()
Entering state 29
Reducing stack by rule 7 (line 26):
$1 = nterm commands ()
$2 = nterm command ()
$3 = token SEMICOLON ()
-> $$ = nterm commands ()
Stack now 0 1 4 7
Entering state 9
Reading a token: end;
Next token is token END ()
Shifting token END ()
Entering state 12
Reading a token: Next token is token SEMICOLON ()
Shifting token SEMICOLON ()
Entering state 20
Reducing stack by rule 1 (line 18):
$1 = token LET ()
$2 = nterm declarations ()
$3 = token IN ()
$4 = nterm commands ()
$5 = token END ()
$6 = token SEMICOLON ()
-> $$ = nterm program ()
Stack now 0
Entering state 2
Reading a token:
Why is it ready to read a token again when I have entered end; ?? What am I missing ? Shouldn't it end here ? If I enter anything now it gives me following error :
Reading a token: let
Next token is token LET ()
syntax error, unexpected LET, expecting $end
Error: popping nterm program ()
Stack now 0
Cleanup: discarding lookahead token LET ()
Stack now 0
My Second doubt is what should be the next step in implementing this compiler ? I mean what more steps are required between this and code generation part ? How do I implement Symbol table now ? and How do I make this parser accept code from file . Till now am providing input in terminal, what if I want to make this accept code from file like my_program.simple ?
Thank You.
declarations :
|INTEGER id_seq IDENTIFIER PERIOD
;
...
I think that you're using a wrong syntax: you state that declarations (as well as idseq and commands) could be epsilon, i.e. an empty production. That because | it's the alternative operator. Alternative between an empty body and the actual pattern. Doesn't make sense.
I think could be the cause of your parser looping.
For a symbol table you can use a map (I hope you're generating C++), declared global outside the parser. Then insert symbols when you seen them.
Before to get a compiler, could be useful to have a working interpreter, it's easier and clarifies many aspects that will be reused building the compiler.