rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar

Home Page:https://docs.rollbar.com/docs/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Item sent with null or missing arguments." when the error is not null or missing

jakehockey10 opened this issue · comments

Hello,

We are occasionally seeing "Item sent with null or missing arguments." in our logs but when reproducing it, the debugger shows that we are indeed sending an object and not null:

image

Can I get some help figuring out why this is showing up in our Rollbar instance? I'd like to stop this from showing up when it seems it shouldn't be in the first place. Thanks!

That method needs either a string or Error object. It can receive other objects and will pass them as extra data in the occurrence, but the first arg should either be a string message or an object that satisfies instanceof Error.

I appreciate the clarification and such quick response. Would you be able to point me in the direction of the documentation on that so I can confirm we don't have any other places where we are using the error method wrong? I was strictly basing my usage off of the TypeScript typings file saying I could pass in just about anything. But your explanation makes sense. Thank you

This is probably the most complete and accurate, though it fails to say the one thing I pointed out above -- either the message or error object needs to be present.

https://docs.rollbar.com/docs/rollbarjs-configuration-reference#rollbarlog

Argument order doesn't matter until it does. For example, passing two error objects, the first will be used and the next will be converted to extra data. Same things if there are two string arguments. Leading with the message and/or error will keep you out of trouble.

Thank you!

This doc change has been submitted.

maybe that can be useful for someone else since it took me a while what we did wrong: in my case the problem was, that we spread the parameters into the function:

Wrong:

class Logger {
  error(...args: LogArgument[]): void {
        this.rollbar.error(...args); 
  }
  ...
}

but LogArgument can be quite every type (including arrays), so i had to change it to that:

Correct:

class Logger {
  public error(arg: LogArgument): void {
      this.rollbar.error(args); 
  }
  ...
}

And it worked as expected.

@waltjones i'm still confused: i prepared a demo here:

https://stackblitz.com/edit/rollbar-angular-demo?file=src/app/services/rollbar.ts

What this shows is that using the current Angular the https://docs.rollbar.com/docs/angular it causes this error.

I found this blogpost https://rollbar.com/blog/error-handling-with-angular-8-tips-and-best-practices/ but this seems repetitive to do it everywhere. Since f.e. HttpErrorResponse is an error that is produced quite often (and there are for sure others), IMO, the docs could be somehow adapted:

Since this seems to be the case according to https://docs.rollbar.com/docs/rollbarjs-configuration-reference#rollbarlog

At least one of message or err must be present.

The typings of LogArgument either is a bit misleading or it should accept also objects?

If i understood correctly, it's more like:

 public log(error: string | Error, ...args: Rollbar.LogArgument[]): Rollbar.LogResult;

My solution seems a bit hacky but maybe there is a cooler solution around to automatically handle also objects?

@Injectable()
export class RollbarErrorHandler implements ErrorHandler {
  constructor(@Inject(RollbarService) private rollbar: Rollbar) {}

  handleError(err: any): void {
    // This is what the docs suggests: this.rollbar.error(err.originalError || err);

    // This is my workaroud:
    this.rollbar.error(...this.sanitizedError(err.originalError || err));
  }

  //
  private sanitizedError(error: any) {
    if (error instanceof Error || error instanceof String) {
      return [error];
    } else if (error instanceof HttpErrorResponse) {
      return [error.message, error];
    } else {
      return ['Error', error];
    }
  }
}