Skip to content

Bug json.exception.type_error.302 #4492

@OyakXD

Description

@OyakXD

Description

I'm creating a bot for discord and it's falling into this exception, for no reason at all, I've already added all kinds of checks, all kinds of try catches, but it breaks all the time when I call it, it even shows the correct token

Reproduction steps

When I turn on the bot it starts everything fine, then at the end it launches the message and breaks

Expected vs. actual results

I get results

Minimal code example

I don't know exactly where the bug is, but when I start this main, this happens

`#include <string>
#include "Bot.h"
#include <nlohmann/json.hpp>
#include <fstream>
#include <iostream>

using namespace std;

int main() {
    ifstream token_file("../token.json");

    if (!token_file.is_open()) {
        cerr << "Erro: Não foi possivel abrir o arquivo token.json" << endl;
        return 1;
    }

    nlohmann::json config;

    try {
        token_file >> config;
        cout << "Conteúdo do JSON carregado: " << config.dump() << endl;

        if (config.contains("token") && !config["token"].is_null() && config["token"].is_string()) {
            string token = config["token"];

            cout << "Iniciando o bot com o token: " << token << endl;
            Bot DiscordBot(token);
            DiscordBot.start();
        } else {
            cerr << "Erro: token inválido." << endl;
            return 1;
        }
    } catch (const nlohmann::json::exception& e) {
        cerr << "Erro ao processar o JSON: " << e.what() << endl;
        return 1;
    } catch (const std::exception& e) {
        cerr << "Erro inesperado: " << e.what() << endl;
        return 1;
    }

    cout << "Programa finalizado com sucesso." << endl;
    return 0;
}` 

My code atuality

here is the token formatting in the json file

`
"token":  "MY_TOKEN"
`

Error messages

terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
  what():  [json.exception.type_error.302] type must be array, but is null
Abortado (imagem do núcleo gravada)

Compiler and operating system

I'm using gcc in linux, but atuality i am using cmake with build

Library version

master

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions