Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Errors in create function with zip-file can get very long #36

Open
lfn3 opened this issue Aug 4, 2016 · 3 comments
Open

Errors in create function with zip-file can get very long #36

lfn3 opened this issue Aug 4, 2016 · 3 comments

Comments

@lfn3
Copy link
Contributor

lfn3 commented Aug 4, 2016

So I totally introduced this one, but I'm not really sure how to deal with it 😕

Right now if you pass a create-function request, using the :zip-file parameter to push a base64 encoded string up, and it errors (e.g. a bad arn), it'll print out that string a couple of times. For my quick hacked together test of a lambda function that uploads itself, that resulted in printing just under six millions characters. (It's in both the request and body bits of the error message)

So I would like to exclude it from the error message, if possible (I'm assuming in general these will be logged somewhere, and a base64 encoded zip isn't amazingly useful as a debugging aid, especially since you could just dump it directly to disk?).

Since it's in an already encoded string the only thing I can think off the top of my head to deal with it is a regex which seems like a bad idea. I'm looking for other ideas of how to remove it, if anyone has any.

Thanks in advance!

@moea
Copy link
Member

moea commented Aug 4, 2016

Are you yourself printing the response map (e.g. REPL etc.), as opposed to elements of the response being printed in Eulalie? Are you using issue-request! as your entrypoint?

If the input is repeated in the error message, you could certainly do something like:

(defn- ellipsize [s & [{:keys [limit] :or {limit 5000}]]
  (if (< limit (count s))
    (str (subs s 0 limit) "...")
    s))

(defmethod eulalie/transform-response-error :eulalie.service/lambda
  [{body :body error :error}]
  (assoc error :message (some-> body platform/decode-json :message ellipsize)))

General-purpose abbreviation of the response's :request key wouldn't work so well - issue-request! in general could just dissoc the request key before returning the map to the user, or use metadata. I'm not sure its presence is generally a hindrance, though, outside of situations like this.

@lfn3
Copy link
Contributor Author

lfn3 commented Aug 4, 2016

Yeah I'm using issue-request and directly printing the result:

(prn (a/<! (ec/issue-request! {:service :lambda
                                        :target :create-function
                                        :creds {...}
                                        :body {:code {:zip-file "abcd"}
                                               :function-name "a-function"
                                               :handler "nodewheel.handler"
                                               :role "23d2071f4882/bad-arn"
                                               :runtime "nodejs4.3"}})))

The full response is here: https://gist.github.com/lfn3/d3231da6550e61e1cb6e7fa66311cd1e, specifically line 20 and 45. I don't think I want to ellipsize the entire body of the request either. Do you think it would be reasonable to replace the encoded body with the untransformed map and ellipsize the zipfile in there?

@moea
Copy link
Member

moea commented Aug 5, 2016

I think it's borderline unreasonable to do that in Eulalie (though you could totally do this in your project by implementing those multimethods), but that may be because I don't look too often at the raw responses. The request maps often get big - if this is a big deal for you, as far as Eulalie changes, I'd personally prefer sticking the request in a :eulalie/request key on the response's metadata map at the point the request is returned to the user - and removing the key from the response map proper.

One other thing is there's stuff in eulalie.lambda.util which presents a slightly higher level API for some common Lambda stuff. A create-function! guy in there which did whatever post-processing it wanted would be totally cool - those guys just return the :body, in any case, so I think the error map would be the only huge thing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants