Catch exceptions without crashing app

2022-02-21 Thread ynfle
`error(e.msg)` crashes the program. If you didn't what to exit, you can just `echo e.msg`

Catch exceptions without crashing app

2022-02-21 Thread Cnerd
That is the main problem

Catch exceptions without crashing app

2022-02-21 Thread PMunch
When I said code sample I meant something more like a minimal reproduction of the code. Something that we could actually run and test.

Catch exceptions without crashing app

2022-02-21 Thread Cnerd
I really can't find any part of the code that would be minimal enough to be tested. But i can give a example of an error i got which crashed the app although i have fixed it now. The was a value error which occured when i used parseFloat on a string(runtime error of course)

Catch exceptions without crashing app

2022-02-21 Thread Cnerd
I wrapped the procedure in a template template safeRunning(action : untyped) = try: action except Exception as e: error(e.msg) Run then i called it here safeRunning:

Catch exceptions without crashing app

2022-02-21 Thread huantian
I'd assume the problem here is that if the entire process of whatever application is run in `bot()`, then if it raises an exception, it would "end" the bot proc to raise it.

Catch exceptions without crashing app

2022-02-21 Thread PMunch
That shouldn't happen, is your `except` handler somehow throwing the same (or a different) error? A code example would help us understand what is going wrong.

variable has incomplete type: struct...

2022-02-21 Thread PMunch
Apparently `{.pure.}` _can_ be attached to an object type, but the manual explains its purpose very poorly. Essentially it is only used for inheritance, specifically when you create a type and attach the `{.inheritable.}` pragma to it. This makes an object which can be inherited from, similar to

Catch exceptions without crashing app

2022-02-21 Thread Cnerd
Jester has a feature in which it catches exceptions of code without crashing the web application. How is this feature implemented. I have used the usual try and except for the proc and although it caught the exception the program still crashes.

Concatenation of seq and array?

2022-02-21 Thread Hlaaftana
Can't we just make the LHS of `&` a `sink` parameter?

Concatenation of seq and array?

2022-02-21 Thread haoliang
although this thread is old, i still wanna add another use case: [foldl](https://nim-lang.org/docs/sequtils.html#foldl.t%2C%2C%2C) let numbers = @[0, 8, 1, 5] digits = foldl(numbers, a & (chr(b + ord('0'))), "") assert digits == "0815" Run

variable has incomplete type: struct...

2022-02-21 Thread drkameleon
Thanks a lot for taking the time and for the super-detailed explanation. What I have been doing so far is write something in Nim, got to the nimcache folder, see what code it produced, go back to Nim and so forth and so on. And yes, I still hadn't found what this `.pure` was supposed to be doing

variable has incomplete type: struct...

2022-02-21 Thread PMunch
Getting the Nim -> C wrapping right can be a bit of a challenge, but once you know what's going on under the hood it's easy to see what you did wrong. So let's dive into what goes on here. First of you started with type ClipboardObj* {.importc: "clipboard_c", header:"libclipboard/

variable has incomplete type: struct...

2022-02-21 Thread drkameleon
lol Barkin up the wrong tree. After 28 years of programming, I guess I must have written my fair share of C, no? (As some unrelated trivia, Arturo was initially written completely in C). The question had mainly to do with Nim and how it translates things to C. Because knowing how to write somet

variable has incomplete type: struct...

2022-02-21 Thread demotomohiro
If you use C library or API, I think you should learn C language. If you know C, you would be able to solve such a problem yourself. If you wrap C library/API without knowing C language, you might write unsafe code. It seems there people trying to use C library/API with Nim without knowing C la

variable has incomplete type: struct...

2022-02-21 Thread auxym
Are you using `sizeof` somewhere? The one time I had that error, I was using `sizeof` on an importc'd object definition. I fixed it by defining all the fields and annotation the object with `{.completeStruct.}`.

variable has incomplete type: struct...

2022-02-21 Thread ynfle
If it's literally just a struct, you `object`

variable has incomplete type: struct...

2022-02-21 Thread drkameleon
You have some point - I have been looking at this part, although I _did_ get it to compile. Any alternative suggestions?

variable has incomplete type: struct...

2022-02-21 Thread ynfle
It's possible using `ref` here is bad because nim will want to control the memory

variable has incomplete type: struct...

2022-02-21 Thread drkameleon
For anyone that might come across a similar issue, I - hope I - fixed it by declaring `ClipboardObj` as: ClipboardObj* {.pure.} = ref object Run * * * **P.S.** Despite the fact that pragmas themselves have always looked a bit "hack-ish" to me, I'm perfectly fine with

variable has incomplete type: struct...

2022-02-21 Thread drkameleon
I'm writing (yet another) wrapper - this time for: My code is here: The relevant part being: type ClipboardObj* {.importc: "clipboard_c"

Correct way have for-loop iteration up to number of only initialized array elements

2022-02-21 Thread ElegantBeef
`newSeqOfCap[int](70)` is just like `newSeq[int](70)` the only difference is the first only sets the capacity and it doesnt add any elements so it's an "empty" allocated sequence. So it avoids more allocation the same but `len` is `0`

Correct way have for-loop iteration up to number of only initialized array elements

2022-02-21 Thread mardiyah
worried get reallocation process, is the same as nr=ew Seq it'll avoid reallocation cost ?

Correct way have for-loop iteration up to number of only initialized array elements

2022-02-21 Thread dwin
Use `newSeqOfCap` instead of newSeq var d = newSeqOfCap[array[2, string]](70) d.add ["foo", "bar"] d,add ["moo", "dar"] for u in d: ... Run