Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return value of Spatie\Valuestore\Valuestore::all() must be of the type array, null returned #23

Closed
LCD344 opened this issue Dec 17, 2018 · 7 comments

Comments

@LCD344
Copy link

LCD344 commented Dec 17, 2018

Hi, we just started using this on a site and during development we have had no problems with it, but we set it up on production, and set an error tracker, and it seems like every now and then we get a weird error from this.
image

It feels on a put line in the settings provider:

class SettingsServiceProvider extends ServiceProvider {


    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot() {
        if (today() > Carbon::create(date('Y'), 12, 14)) {
            $year = date('Y') + 1;
        } else {
            $year = date('Y');
        }
        $this->app->settings->put('registration_year', $year);
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register() {
        $this->app->singleton('settings', function ($app) {
            return Valuestore::make(database_path('settings.json'));
        });
    }
}

The line it always fails on is: $this->app->settings->put('registration_year', $year); and the error is always

Return value of Spatie\Valuestore\Valuestore::all() must be of the type array, null returned

So far we haven't managed to recreate it, but it bothers me....

any chance you know what could be causing it? thanks!

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

@jason-guru
Copy link

It might be a little late and I hope you have already solved the problem, and for others having the same issue,
initialize the settings.json ( where you're going to store the key value pairs) file with json object brackets.
{ }

@nuz
Copy link

nuz commented Oct 4, 2019

It might be a little late and I hope you have already solved the problem, and for others having the same issue,
initialize the settings.json ( where you're going to store the key value pairs) file with json object brackets.
{ }

Could you be more specific about how to solve this?
Because I also get this error and I can't find where and when it happens and how to fix it.

@joostvanhoof
Copy link

joostvanhoof commented Feb 14, 2020

I'm running into this issue as well, and it's really difficult to debug as it seemingly randomly throws this error. @jason-guru I think your solution is for when you settings.json file is empty, right? My settings.json file already has values, so this won't solve the issue.

I initially thought that this error was caused by 2 processes that simultaneously tried to update the settings.json file. So I changed this so that each process has a different settings file, yet the error still occurs.

@nuz did you eventually solve it?

@nuz
Copy link

nuz commented Feb 14, 2020

I'm running into this issue as well, and it's really difficult to debug as it seemingly randomly throws this error. @jason-guru I think your solution is for when you settings.json file is empty, right? My settings.json file already has values, so this won't solve the issue.

I initially thought that this error was caused by 2 processes that simultaneously tried to update the settings.json file. So I changed this so that each process has a different settings file, yet the error still occurs.

@nuz did you eventually solve it?

Finally I removed the package and put my values from database to config file.

@merlin-41
Copy link

Return value of Spatie\Valuestore\Valuestore::all() must be of the type array, null returned

Can you please help me to fix the above error.

@eriksmets
Copy link

I fixed it by encoding the data in my array to utf-8. (cfr example function from Stack Overflow)

function utf8ize($d) {
 if (is_array($d)) {
        foreach ($d as $k => $v) {
            $d[$k] = utf8ize($v);
        }
    } else if (is_string ($d)) {
        return utf8_encode($d);
    }
    return $d;
}

freekmurze added a commit that referenced this issue Aug 21, 2020
* make sure to all() method are always return an array

* Update ValuestoreTest.php

Co-authored-by: Freek Van der Herten <freek@spatie.be>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants