Try to read a file, parse it as JSON, and return the resulting document. It will NOT throw if any errors are encountered, it will just return an empty JSON object and will log trace events for the errors encountered.
| 584 | // It will NOT throw if any errors are encountered, it will just return an empty |
| 585 | // JSON object and will log trace events for the errors encountered. |
| 586 | ACTOR Future<Optional<json_spirit::mObject>> tryReadJSONFile(std::string path) { |
| 587 | state std::string content; |
| 588 | |
| 589 | // Event type to be logged in the event of an exception |
| 590 | state const char* errorEventType = "BlobCredentialFileError"; |
| 591 | |
| 592 | try { |
| 593 | state Reference<IAsyncFile> f = wait(IAsyncFileSystem::filesystem()->open( |
| 594 | path, IAsyncFile::OPEN_NO_AIO | IAsyncFile::OPEN_READONLY | IAsyncFile::OPEN_UNCACHED, 0)); |
| 595 | state int64_t size = wait(f->size()); |
| 596 | state Standalone<StringRef> buf = makeString(size); |
| 597 | int r = wait(f->read(mutateString(buf), size, 0)); |
| 598 | ASSERT(r == size); |
| 599 | content = buf.toString(); |
| 600 | |
| 601 | // Any exceptions from hehre forward are parse failures |
| 602 | errorEventType = "BlobCredentialFileParseFailed"; |
| 603 | json_spirit::mValue json; |
| 604 | json_spirit::read_string(content, json); |
| 605 | if (json.type() == json_spirit::obj_type) |
| 606 | return json.get_obj(); |
| 607 | else |
| 608 | TraceEvent(SevWarn, "BlobCredentialFileNotJSONObject").suppressFor(60).detail("File", path); |
| 609 | |
| 610 | } catch (Error& e) { |
| 611 | if (e.code() != error_code_actor_cancelled) |
| 612 | TraceEvent(SevWarn, errorEventType).errorUnsuppressed(e).suppressFor(60).detail("File", path); |
| 613 | } |
| 614 | |
| 615 | return Optional<json_spirit::mObject>(); |
| 616 | } |
| 617 | |
| 618 | // If the credentials expire, the connection will eventually fail and be discarded from the pool, and then a new |
| 619 | // connection will be constructed, which will call this again to get updated credentials |
nothing calls this directly
no test coverage detected