I am getting This Error "String index out of range: -1".
does this have something to do with the input data like any character or something?
Can anyone please explain me the root cause of this error and how do i resolve?
Related
I am trying to insert a document into mongodb under the inspections collection but no matter what I try, I get an error!
The code I am trying:
db.inspections.insertOne({
"_id": 20032-2020-ACME,
certificate_number: 9998888,
business_name: "ACME Explosives",
date: newDate("09-05-2022"),
result: "Business Padlocked",
sector: "Explosive Retail Dealer-999",
{
"address":"number->1721" "street-> Boom Road" "city->BRONX" "zip->10463"}
}
This is the error I keep getting:
E QUERY [js] uncaught exception: SyntaxError: expected property name, got '{' :
I have tried to replace the brackets, tried formatting in a different way, tried using without quotes or switching quotes around but each attempt gives me this same error.
How can I fix this?
The error actually tells you what is wrong.
The item you are trying to insert is not valid json.
Most likely you have forgotten to put a key before the { that sits before "address". Also, in that same line you don't have any comma's to seperate the key value pairs.
I believe you will have more success with
db.inspections.insertOne({
"_id": "20032-2020-ACME",
certificate_number: 9998888,
business_name: "ACME Explosives",
date: newDate("09-05-2022"),
result: "Business Padlocked",
sector: "Explosive Retail Dealer-999",
address: {
"number":"1721",
"street":"Boom Road",
"city":"BRONX",
"zip":"10463"
}
}
The address: part is what it is truely complaining about now. Most likely it would have complained about the lack of comma's after fixing address:. Or your use of -> instead of :.
Also, it may also be that keys must be quoted.
EDIT: Also just noticed that your original ID is probably being interpreted as integer minus integer minus string/unknown var. I can't say what the effect might be of that, but I'm gonna assume you want that to be the id, as a string. To do so, I've put quotes around the 20032-2020-ACME
I use a function insertOne to insert an object. I have place correct colon and also correct commas then why this error come. Thanks in Advance.
This is my code
db.items.insertOne({Name:"Oppo",Price:"45000",Ritems:"345",Sold:"45","Rating:"3.5",once"twos"})
Error is this
uncaught exception: SyntaxError: missing : after property id :
#(shell):1:78
>
I think that your "" are misplaced. I think this way would be better ??
db.items.insertOne({Name:"Oppo",Price:"45000",Ritems:"345",Sold:"45",Rating:"3.5",once:"twos"})
Also the error message is telling you about the Id column, you should check if you need to set it yourself or if your database has an auto-increment ID.
I got some account issues in the SCN so I make a attempt here.
We switched to Unicode and got some issues with that. INFTY_TAB = PS+2. This coding gets an error that "the offset + length is exceeding".
I found some hints but couldn't really figure out how to fix this. And even when I manage to fix those errors I got a new error called 'Iclude-Report %HR_P9002 not found'. The IT is still there so is there something else I can check?
Definition of PS:
DATA: BEGIN OF PS OCCURS 0.
*This indicates if a record was read with disabled authority check.
data: authc_disabled(1) type c.
DATA: TCLAS LIKE PSPAR-TCLAS.
INCLUDE STRUCTURE PRELP.
DATA: ACRCD LIKE SY-SUBRC.
DATA: END OF PS.
TCLAS is a char(1) field.
This is the part where the error pops up:
INFTY_TAB = PS+2.
Error: I had to translate so sorry for some mistakes that could appear.
Offset and Length (=2432) exceed the length of the character based beginning (=2430) of the structure.
Depends on the length of INFTY_TAB. You have to explicitly set length:
INFTY_TAB = PS+2(length).
Official information is here. The important point to note is that the inclusion of SY-SUBRC (which is an INT4 field) places a limit to the range of fields you can access using this (discouraged) method of access.
ASSIGN field+off TO is generally forbidden from a syntactical
point of view since any offset <> 0 would cause the range to be
exceeded.
Although the sentence above is related to ASSIGN command, it is also valid for this situation.
I'm currently working on an elixir project that parses XML from an API and inserts data into postgres using postgrex.
Most inserts work fine, however for the odd insert I get this error. I've seen a lot of other people facing this error, but I'm not to sure how to solve it in Elixir.
23:52:32.402 [error] Process #PID<0.224.0> raised an exception
** (KeyError) key :constraint not found in: %{code: :character_not_in_repertoire, file: "wchar.c", line: "2011", message: "invalid byte sequence for encoding \"UTF8\": 0xe3 0x83 0x22", pg_code: "22021", routine: "report_invalid_encoding", severity: "ERROR"}
(pipeline_processor) lib/worker.ex:133: PipelineProcessor.Worker.recursive_db_insert/1
(pipeline_processor) lib/worker.ex:47: PipelineProcessor.Worker.process_article/1
(pipeline_processor) lib/worker.ex:17: PipelineProcessor.Worker.request_article/0
I'm aware that the error is actually due to accessing an invalid property of the map. However I'm trying to solve the issue that postgrex is giving.
My postgrex insert code:
sql_string = "INSERT INTO articles (title, source, content) VALUES ($1, $2, $3) RETURNING id"
{:ok, pid} = Postgrex.Connection.start_link(Application.get_env(:pipeline_processor, :db_details))
response = Postgrex.Connection.query(
pid,
sql_string,
[article.title, article.source, article.content]
)
Postgrex.Connection.stop(pid)
Is there anyway in Elixir to scrub out invalid bytes so that these inserts can succeed? Or for some way to have postgres handle it?
Thanks
As you already guessed postgres is complaining that you are inserting invalid UTF8 into a text type. I would initially try to fix the bad encodings if you cannot do that you can use a combination of String.codepoints/1 and String.valid_character?/1 to either scrub or escape the invalid bytes.
Certain words in the Turkish stemmer is causing SnowballProgram to throw an index out of range exception. Can anybody help me to solve this problem?