Crystal: Invalid memory access (signal 11) at address 0x370

Created on 8 Nov 2018  ยท  8Comments  ยท  Source: crystal-lang/crystal

code :

get "/route" do |env|
  result = [] of Hash(String, String | Int32 | Int64)

  somevar = env.params.query["sv"]?

  if !somevar.nil?
    phone_imei = phone_imei.to_s
    check_idb = IDB["col"].find_one({"col" => somevar})

    if check_idb # error
      idb_data = {
        "imei"  => somevar,
        "phone" => check_idb["phone"].to_s,
      }
      result << idb_data
    else # success
      req_api = HTTP::Client.post "https://www.example.com", form: "key=val", headers: HTTP::Headers{"Content-Type" => "multipart/form-data"}
      if req_api.success?
        puts "success"
        api_res = JSON.parse api_res
        # define idb_data Hash (String, String | Int32 | Int64)
        # mongo update
        result << idb_data
      end
    end
  end
  result.to_json
end

result :

2018-11-09 03:00:59 +07:00 200 GET /route?uwu=afa 2103.37ms                            
success
2018-11-09 03:01:27 +07:00 200 GET /route?uwu=afa 2061.21ms                            
Invalid memory access (signal 11) at address 0x370                                                                   
[0x5bf836] *CallStack::print_backtrace:Int32 +118                                                                    
[0x50b5a0] __crystal_sigfault_handler +192                                                                           
[0x7f2acd3e8390] ???                                                                                                 
[0x79d516] *Pointer(Hash(String, Int32 | Int64 | String) | Hash(String, Int64 | String) | Hash(String, String)) +6   
[0x79d29a] *Array(Hash(String, Int32 | Int64 | String)) +10                                                          
[0x7f2ace8fb3c0] ???                                                                                                 
invalid

Most helpful comment

I've failed to compile your code.
Don't you have a reproducable example? This is usually done by removing unnecessary lines and dependencies from example until error stop to appear.

All 8 comments

Unused type cause error ?

result = [] of Hash(String, String | Int64) (working)
result = [] of Hash(String, String | Int32 | Int64) (error)

I've failed to compile your code.
Don't you have a reproducable example? This is usually done by removing unnecessary lines and dependencies from example until error stop to appear.

yes sir, but why unnecessary lines made error, and i think should not

To answer the question we (at least me) need a short piece of code, e.g. one that can be run on https://carc.in/ and see an error.
Your code has too much dependencies, it is difficult to understand what is an error.
Without short self-sustainable code example chances that the error will be fixed or even found are low. So it would be a lot of help if you can remove unnecessary lines and dependencies one by one (but error still must appear, that's the point. If it stopped appearing - return the line you just deleted and try deleting another ones). I understand that it can be difficult and take quite a some time, but without it the error will likely remains not fixed.

โ€โ€โ€Ž โ€โ€โ€Ž โ€โ€โ€Ž โ€โ€โ€Ž

lltry sir

@codenoid it does not look like the result associated with the code provided. In your code somevar is always nil because you never use a query parameter called "sv". Therefore it should immediately return an empty result array as json. So it can never print "success", not even once.

I'll close this as invalid until we get some code we can run and reproduce the error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oprypin picture oprypin  ยท  3Comments

will picture will  ยท  3Comments

asterite picture asterite  ยท  3Comments

cjgajard picture cjgajard  ยท  3Comments

lgphp picture lgphp  ยท  3Comments