facebook / facebook/hermes

Function caller info

Open
#414 7 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
11.3k
Forks
859
Avg merge
1h 30m
Merged PRs (30d)
3

Description

## Problem

I'm using a custom implementation of a Logger which outputs all logs in the following format:

```
[current time] [function that invoked log()]: [log message]
```

My log function looks like this:

```ts
function formatCaller(caller: Function): string {
if (!caller) return '{?}:';
else return `{${caller.name}}: `;
}

export function log(...messages: unknown[]): void {
let caller = '{?}:';
try {
caller = formatCaller(log.caller);
} catch {}
const joinedMessage = messages.map((m) => (typeof m === 'string' ? m : JSON.stringify(m))).join(' ');
console.log(caller + joinedMessage);
}
```

On JSC (iOS) the caller name is correctly retrieved, but on Hermes `log.caller` evaluates to null because caller information is not available in Hermes bytecode. This makes it extremely difficult to trace breadcrumbs back when trying to find the source of an error that pops up in your Sentry/Crashlytics/...

## Solution

Add `[currentFunction].caller` information. Since the function's code is stored as bytecode, I'm assuming only `name` and `arguments` are available properties, `toString()` should just return the `name` instead of the function's code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.