Repository: promptfoo/promptfoo
Issue: Unable to share eval
Root cause: External Dependency Breakage

Hey,
great library! I created an evaluation and tried the share feature `npx promptfoo@latest share`

but an internal server error occurs:
```
FetchError: invalid json response body at https://api.promptfoo.dev/api/eval reason: Unexpected token 'I', "Internal s"... is not valid JSON
```

It works via the web interface, but when opening the shared link, it fails to load:
```
DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'ResultsViewStorage' exceeded the quota.
```

Hello!

I am experiencing the same issue with a self-hosted instance of promptfoo. I followed the steps for building the docker image but I got the same error:

![image](https://github.com/user-attachments/assets/5459d57d-c2be-4c94-94f4-b3e9ee62720c)

It seems like a problem with the database migrations of sqlite. The tables don't seem to be created.

![image](https://github.com/user-attachments/assets/0180f4fe-61ea-42d4-96d6-693cc5394774)




Hey, I'm getting the same error when using `promptfoo eval --share` with 0.75.1 (`promptfoo eval` is working fine):
```
/Users/robin/.nvm/versions/node/v21.7.3/lib/node_modules/promptfoo/node_modules/node-fetch/lib/index.js:273
                                return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
                                                           ^
FetchError: invalid json response body at https://api.promptfoo.dev/api/eval reason: Unexpected token 'I', "Internal s"... is not valid JSON
    at /Users/robin/.nvm/versions/node/v21.7.3/lib/node_modules/promptfoo/node_modules/node-fetch/lib/index.js:273:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async createShareableUrl (/Users/robin/.nvm/versions/node/v21.7.3/lib/node_modules/promptfoo/dist/src/share.js:55:27)
    at async runEvaluation (/Users/robin/.nvm/versions/node/v21.7.3/lib/node_modules/promptfoo/dist/src/commands/eval.js:118:63)
    at async doEval (/Users/robin/.nvm/versions/node/v21.7.3/lib/node_modules/promptfoo/dist/src/commands/eval.js:240:5) {
  type: 'invalid-json'
}
```

I'm getting the same error when running `promptfoo share` by the way.

👀 

@RobinGroundfog any output on the server side?

Hummmm, this is fixed now so I can't reproduce the issue (I didn't change anything) 🤔 I will try to capture it if that happens again

Hello, I am getting the same issue as Robin when I try to run `npx promptfoo@latest share` with an eval ID:

```
npx promptfoo@latest share eval-2024-08-13T17:12:55
Create a private shareable URL of your eval on app.promptfoo.dev?

To proceed, please confirm [Y/n] y

/Users/ktloh/.npm/_npx/81bbc6515d992ace/node_modules/node-fetch/lib/index.js:273
                                return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
                                                           ^
FetchError: invalid json response body at https://api.promptfoo.dev/api/eval reason: Unexpected token 'I', "Internal s"... is not valid JSON
    at /Users/ktloh/.npm/_npx/81bbc6515d992ace/node_modules/node-fetch/lib/index.js:273:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async createShareableUrl (/Users/ktloh/.npm/_npx/81bbc6515d992ace/node_modules/promptfoo/dist/src/share.js:55:27)
    at async createPublicUrl (/Users/ktloh/.npm/_npx/81bbc6515d992ace/node_modules/promptfoo/dist/src/commands/share.js:15:17)
    at async /Users/ktloh/.npm/_npx/81bbc6515d992ace/node_modules/promptfoo/dist/src/commands/share.js:64:17 {
  type: 'invalid-json'
}

Node.js v20.14.0
```
The share works fine on the local server.

cc: @mldangelo 

I'm having the same issue. In 0.89.4 I get this 

```
$ promptfoo share                
(node:9958) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Create a private shareable URL of your eval on app.promptfoo.dev?

To proceed, please confirm [Y/n] Y
Network error while creating shareable URL: FetchError: invalid json response body at https://api.promptfoo.dev/api/eval reason: Unexpected token '<', "<html>
<h"... is not valid JSON
View results: null
```

Evidently it doesn't like the "<" token in my prompt. `promptfoo view` works fine.

Hey everyone, thanks for the reports here.

It's been a while since the last activity on this issue, and a lot has changed in the share functionality since then. Looking back at what was reported:

The `FetchError: invalid json response body` errors were caused by our API returning 500 errors or HTML error pages instead of proper JSON responses. These were transient server-side issues that have since been resolved. @RobinGroundfog even noticed their issue "fixed itself" without any changes on their end, which is consistent with this.

On the client side, we've also made the error handling much more robust. If the server does return a non-JSON response now, you'll get a clear error message with debug info instead of a confusing JSON parse failure.

For those who were hitting 413 Payload Too Large (like in the screenshot from @RenzoBenemerito), we now upload results in chunks (~900KB each) with compression, so large evals should work fine.

A few things that came up here are actually separate issues:

- The `QuotaExceededError` when *viewing* a shared link in the browser is a different problem - that's being tracked in #1906 and #1731
- Self-hosted setup issues with missing SQLite tables would need a separate issue with your Docker configuration

I'm going to close this one out given the age and the fixes that have landed. If you're still having trouble sharing evals on a recent version (0.100+), please open a fresh issue and include the output from running with `LOG_LEVEL=debug` - that'll give us the details we need to dig in.

Thanks again for taking the time to report these!