[metro-file-map] An error a watcher backend reports ends the server, since nothing listens for it

Aperta Adatta ai principianti
#2,143 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
tooling

Direzione di ricerca

Inizia da packages/metro-file-map/src/Watcher.js, in corrispondenza della sottoscrizione del backend a onFileEvent, poi leggi AbstractWatcher.js per vedere come vengono emessi gli errori del backend. L’issue suggerisce di sottoscriversi anche a onError del backend; usa la riproduzione collegata per verificare che venga segnalato un errore del watcher e che il server Metro continui a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Reproduction: https://github.com/YevheniiKotyrlo/metro-file-map-watcher-error

When a watcher backend reports an error, the Metro server exits. Watcher subscribes each backend it starts with onFileEvent only (Watcher.js#L332), and AbstractWatcher.emitError emits 'error' on the backend's own EventEmitter (AbstractWatcher.js#L87). With no 'error' listener, Node's EventEmitter throws the error, so any error a backend reports ends the process: here FallbackWatcher's .catch of a change it could not lstat (FallbackWatcher.js#L295), and as well the other emitError calls in FallbackWatcher and NativeWatcher, and a Watchman client error.

Steps (metro 0.87.2, and metro-file-map built from main at b8ac7a77a114ce1199c5e2b3ef2cca0a5b3d0aa8; Node 26.12.1, npm 12.2.1, Linux under WSL 2):

  1. Clone the reproduction and npm install. It is a plain Metro project whose index.js requires watched/value.js, and whose metro.config.js sets resolver.useWatchman: false.
  2. npx metro serve, and wait for Welcome to Metro.
  3. In a second terminal, in the same folder, chmod 000 watched.

For main: between steps 1 and 2, yarn install --frozen-lockfile and node scripts/build.js in a react/metro checkout, then node use-metro-main.js <the checkout>, which puts its packages/metro-file-map/build in place of the installed metro-file-map/src.

Expected: the watcher reports that it cannot read the folder, and the server goes on.

Seen, on 0.87.2 and on main alike: the server exits with code 1:

Error: EACCES: permission denied, lstat '…/metro-file-map-watcher-error/watched/watched'
    at async Object.lstat (node:internal/fs/promises:1887:18)
    at async #processChange (…/metro-file-map-watcher-error/node_modules/metro-file-map/src/watchers/FallbackWatcher.js:244:20)
Emitted 'error' event at:
    at FallbackWatcher.emitError (…/metro-file-map-watcher-error/node_modules/metro-file-map/src/watchers/AbstractWatcher.js:77:19)
    at …/metro-file-map-watcher-error/node_modules/metro-file-map/src/watchers/FallbackWatcher.js:212:25 {
  errno: -13,
  code: 'EACCES',
  syscall: 'lstat',
  path: '…/metro-file-map-watcher-error/watched/watched'
}

stopWatching() removes every listener (AbstractWatcher.js#L76), so an error reported while the watcher shuts down throws the same way. Subscribing the backend's onError beside its onFileEvent would let the file map report the error instead.

Lingua principale
JavaScript
Stelle
5.7k
Fork
711
Merge medio
2g 18h
PR unite (30g)
66

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di react/metro

Tutte le issue di react/metro

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.