Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ryman
    @Ryman
    @ruizander You can implement an error handler and print the error.message: See here for basic structure https://github.com/nickel-org/nickel.rs/blob/master/examples/example.rs#L115-L131
    Ryman
    @Ryman
    This video might be of interest to people here! https://www.youtube.com/watch?v=Ae44aZAac3w
    Masood Ahmed
    @masoodahm
    hello all
    is there a way to read form post data from nickel request object? I have seen the example with reading the request body into a string but that does not gives me individual form element values
    if reading the request data into a hashmap does not exist, then I will write my own
    Masood Ahmed
    @masoodahm
    In case such a method does not already exist please take a look at this http://is.gd/HtbeqW, since nickel already uses the crate url there is no new dependency for this code, and the request object in function parameters can be replacesd by &self when you put it in the nickel::Request object
    nickel is already using the url crate for parsing url query string, since the nature of data in querystring and in form post is same we can use same method for both cases
    I could have created a pull request but I wasn't sure if nickel already have a method for geting post form data into a hashmap
    in case it doesn't have such a method, I will create a pull request
    ruizander
    @ruizander
    @Ryman : fantastic!! it worked! I was able to println the error message... is there a way to print the stack trace?
    Ryman
    @Ryman
    @masoodahm You might want to add to the discussion here (and also check the linked implementation): https://github.com/nickel-org/nickel.rs/issues/240#issuecomment-145459986
    @ruizander add RUST_BACKTRACE=1 before your command, e.g. RUST_BACKTRACE=1 cargo test
    ruizander
    @ruizander
    @Ryman I've noticed that it's easy to custom the most popular errors (404 - not found, 401 - unauthorized, 403 - forbidden, etc) but how exceptions must be handled?
    ruizander
    @ruizander
    I've seen articles about developing on express.js, and some of them suggest the use of javascript domains... how it's done on rust land?
    Ryman
    @Ryman
    @ruizander By exceptions you mean 5xx errors? Or exceptions in the C++/Java sense?
    Do you have a link available for 'javascript domains', I'm not really sure what that means?
    ruizander
    @ruizander
    @Ryman I mean exceptions in c++/java way... here is a good link about this subject: https://www.joyent.com/developers/node/design/errors
    considering this article, I mean "operational errors"
    ruizander
    @ruizander
    Ryman
    @Ryman
    @ruizander Thanks for the links!
    Ryman
    @Ryman
    It looks like in general this is talking about unchecked exceptions, which rust doesn't have, we have panic, but that should only be used in extreme cases (often highlighting a bug). In the case of panic the thread currently dies (we would need to wait for catch_panic to stabilize to allow custom behaviour here)
    Matt Banister
    @mattbanister
    @ruizander @Ryman It seems to me that the idiom for dealing with operational errors is just different. Javascript operations that may fail take a callback of the form function (err, res) {...} and rust operations should return a result type that you can match against.
    match res { 
        Ok(v) => // do something with v, 
        Err(err) => // handler err
     }
    Ryman
    @Ryman
    @mattbanister Pretty much yeah, for 'operational errors' you'll want to do the same as the linked article, handle it, or propagate the type. In nickel you may also want to use try_with!, as seen in an old example here: https://github.com/Ryman/nickel-todo-backend/blob/master/src/main.rs#L77
    @ruizander If you have a more concrete example of what you want to handle, I can take a look :)
    Matt Banister
    @mattbanister
    Ah okay thanks @Ryman that makes sense
    Off topic but I went to a meetup about this project last night : http://maidsafe.net/. Ambitious project (it basically aims to be a replacement for the internet) and their entire codebase is rust.
    Ryman
    @Ryman
    @mattbanister Cool, I meant to visit one of their meetups in London but got sidetracked. The meetup was good?
    ruizander
    @ruizander
    @Ryman I dont' have right now, but I'm learning rust and nickel in order to port a node.js website that I'm currently working...
    Ryman
    @Ryman
    ok! :+1:
    Matt Banister
    @mattbanister
    @Ryman yeah their platform is interesting. The idea is a kind of distributed computation/storage platform based on distributed hash tables with rewards built in for participating. It has some similarities with tor, blockchain and bittorrent if that makes any sense
    Also interesting that all of their code has been rewritten in rust
    ruizander
    @ruizander
    @Ryman i'd like to ask: if you have a nickel app that starts and connects to a database server and, after some queries, the database server goes offline... what kind of error does the nickel app throw?
    Ryman
    @Ryman
    @ruizander Well, depends on how your database code deals with things :P But currently, the two that I know of nickel-sqlite and nickel-postgres will panic due to unwraps, which should 500 but doesn't (see hyperium/hyper#676 as a proposed fix for handling panics better in hyper). You can implement this behavior yourself with a frontloaded Middleware which sets the default StatusCode to 500 or whatever you need, and that will be used if things panic.
    Lorenz Brun
    @lorenz
    Is there any doc on how to do error handling in nickel?
    Simon Persson
    @SimonPersson
    @lorenz Yes! The doc mentions how to create a NickelError here: http://docs.nickel.rs/nickel/struct.NickelError.html. The examples show how to register custom handlers for different error codes: https://github.com/nickel-org/nickel.rs/blob/master/examples/example.rs#L127. Is that what you wanted to do?
    Masood Ahmed
    @masoodahm
    hi, I know in nickel a middlware have a different meaning than other frameworks, but is there a mechanism to have a function that runs before every get and post to check if the user is logged in or not, if he/she is then continue to the handler else redirect to login
    ruizander
    @ruizander
    @Ryman i'd like to understand better the lifetime concepts on rust... although I've read the book, I think I need some exercises to really understand this... could you please help?
    I was trying to understand when to use str / String, and I've noticed &'a str a lot, but I don't get it..
    Lorenz Brun
    @lorenz
    @SimonPersson Thanks! I'll look into it.
    Simon Persson
    @SimonPersson
    @masoodahm I replied in the issue you opened :)
    @ruizander Is there something that feels particularly confusing about lifetimes?
    @ruizander Regarding String/&str, you generally want to use &str, simply because you can create a &str cheaply from a String, but not the other way around.
    Simon Persson
    @SimonPersson
    Of course there are times when you really need an owned string, then you must use String (and the compiler will tell you if you need to).
    Masood Ahmed
    @masoodahm
    yes thanks @SimonPersson a little bit more help, if you don't mind, the mound example on github says " * the request uri must be reset so that it can be matched against other middleware."
    how do i reset the request uri
    Simon Persson
    @SimonPersson
    @ruizander Perhaps this guide to learning Rust by writing a bunch of linked lists can be helpful to understand references and lifetimes in Rust?
    @masoodahm Aha, that's just a justification for why we that test case exists. It just means that after the middleware is incoked, the request uri is reset to whatever it was before. This is due to the nature of the mount middleware. See the actual implementation here.
    Masood Ahmed
    @masoodahm
    ok how do I redirect in the middleware of server.mount
    if i do res.redirect, it says use of moved value res
    here is what I have tried so far http://is.gd/1P9dYA