From 87833c759ecf0f54cf0f8d616379619371742713 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 22 Dec 2021 03:17:46 -0800 Subject: [PATCH] Fixed an exception when logging unserializable errors Reviewed By: nikoant Differential Revision: D33276412 fbshipit-source-id: 615b2cc523a3ab4445a1208f460753b8634f6812 --- desktop/flipper-plugin/src/__tests__/api.node.tsx | 1 + desktop/flipper-plugin/src/index.ts | 1 + docs/extending/flipper-plugin.mdx | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/desktop/flipper-plugin/src/__tests__/api.node.tsx b/desktop/flipper-plugin/src/__tests__/api.node.tsx index 2cb6c20fc..f255f4b54 100644 --- a/desktop/flipper-plugin/src/__tests__/api.node.tsx +++ b/desktop/flipper-plugin/src/__tests__/api.node.tsx @@ -59,6 +59,7 @@ test('Correct top level API exposed', () => { "path", "produce", "renderReactRoot", + "safeStringify", "sleep", "styled", "textContent", diff --git a/desktop/flipper-plugin/src/index.ts b/desktop/flipper-plugin/src/index.ts index 406c11842..d30e39886 100644 --- a/desktop/flipper-plugin/src/index.ts +++ b/desktop/flipper-plugin/src/index.ts @@ -134,6 +134,7 @@ export {textContent} from './utils/textContent'; import * as path from './utils/path'; export {path}; export * from './utils/uuid'; +export {safeStringify} from './utils/safeStringify'; // It's not ideal that this exists in flipper-plugin sources directly, // but is the least pain for plugin authors. diff --git a/docs/extending/flipper-plugin.mdx b/docs/extending/flipper-plugin.mdx index bafddb32e..6aef69f8d 100644 --- a/docs/extending/flipper-plugin.mdx +++ b/docs/extending/flipper-plugin.mdx @@ -1166,6 +1166,12 @@ Usage: `uuid()` Returns UUID V4. +### safeStringify + +Usage: `safeStringify(dataStructure)` + +Serialises the given data structure using `JSON.stringify`, but doesn't throw if the processes failed, but rather returns a `` string. + ## TestUtils The object `TestUtils` as exposed from `flipper-plugin` exposes utilities to write unit tests for Sandy plugins.