Commit Graph

2 Commits

Author SHA1 Message Date
Julien a07dbaa0fd
Gracefully handle errors that don't implement toString ()
In JavaScript you can throw *anything*, not just errors. Our error
handler was falling back to `”” + err` to stringify the error, however
if that object does not implement `toString()`, the error handler itself
throws with a type error.

We can handle this more gracefully using `util.inspect`, which does not
crash, unless the error is very naughty and overrides the
`util.inspect.custom` hook and throws in that.

Fixes https://github.com/pulumi/pulumi/issues/18068
2024-12-20 14:29:09 +00:00
Julien 6e39175f8d
Allow accessing configuration in Node.js dynamic providers ()
This PR follows https://github.com/pulumi/pulumi/pull/17673 by adding a
`configure` method to Node.js dynamic providers.

The `configure` method of the `ResourceProvider` interface is called
with a `ConfigureRequest` that holds the stack’s configuration, and
allows the provider implementation to retrieve and store configuration
values for later use.

```typescript
class MyResourceProvider implements pulumi.dynamic.ResourceProvider {
    private password: string;

    async configure(req: pulumi.dynamic.ConfigureRequest): Promise<void> {
        this.password = req.config.require("password");
    }

    async create(props: any): Promise<pulumi.dynamic.CreateResult> {
      // use self.password
    }
}
```

---------

Co-authored-by: Will Jones <will@sacharissa.co.uk>
2024-11-07 14:34:11 +00:00