Error 500 : Could not resolve service

Hello,

I am currently developping a nextcloud app for the first time and I got this error then trying to use services :

Could not resolve service! Class "service" does not exist

Service :

namespace OCA\Accountancy\Service;

use OCA\Accountancy\Db\AccountMapper;

class AccountService {

    private AccountMapper $mapper;

    public function __construct() {
	}

    public function findAll(string $userId): array {
        return $this->mapper->findAll($this->userId);
	}
}

Mapper :

namespace OCA\Accountancy\Db;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;

class AccountMapper extends QBMapper {

    public function __construct(IDBConnection $db) {
        parent::__construct($db, 'accountancy_accounts');
    }

    public function findAll(string $userId) : array {
    }
}

And the controller :

namespace OCA\Accountancy\Controller;

use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;

use OCA\Accountancy\Service\AccountService;

class AccountAPIController extends ApiController {

    private AccountService $accountService;
    private ?string $userId;

    	/**
	 * @param string $appName
	 * @param IRequest $request
	 * @param AccountService $service
	 * @param $userId
	 */
    public function __construct(string $appName, IRequest $request, AccountService $service, ?string $userId = null) {
		parent::__construct($appName, $request);
		$this->accountService = $service;
		$this->userId = $userId;
	}

    	/**
	 * @NoAdminRequired
	 * @CORS
	 * @NoCSRFRequired
	 *
	 * Return all of the boards that the current user has access to.
	 * @throws StatusException
	 */
	public function index() : DataResponse {
		$accounts = $this->accountService->findAll($this->userId);
		return new DataResponse($accounts, HTTP::STATUS_OK);
	}

}

I really don’t see what I missed. Could it be related to the migration or some other config ?

I am running on docker if thats help.

Any help would be appreciated !

Edit
Full log entry :

{
    "reqId": "g0YVIYTHLAaXQjpsMIf5",
    "level": 3,
    "time": "2022-11-28T21:42:09+00:00",
    "remoteAddr": "172.22.0.1",
    "user": "nextcloud",
    "app": "index",
    "method": "GET",
    "url": "/apps/accountancy/api/v1/accounts",
    "message": "Could not resolve service! Class \"service\" does not exist",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
    "version": "24.0.6.1",
    "exception": {
        "Exception": "OCP\\AppFramework\\QueryException",
        "Message": "Could not resolve service! Class \"service\" does not exist",
        "Code": 0,
        "Trace": [
            {
                "function": "OC\\AppFramework\\Utility\\{closure}",
                "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                "type": "->",
                "args": [
                    "*** sensitive parameters replaced ***"
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                "line": 108,
                "function": "array_map",
                "args": [
                    {
                        "__class__": "Closure"
                    },
                    [
                        {
                            "__class__": "ReflectionParameter",
                            "name": "appName"
                        },
                        {
                            "__class__": "ReflectionParameter",
                            "name": "request"
                        },
                        "*** sensitive parameters replaced ***",
                        {
                            "__class__": "ReflectionParameter",
                            "name": "userId"
                        }
                    ]
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                "line": 116,
                "function": "buildClass",
                "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                "type": "->",
                "args": [
                    {
                        "__class__": "ReflectionClass",
                        "name": "OCA\\Accountancy\\Controller\\AccountAPIController"
                    }
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                "line": 133,
                "function": "resolve",
                "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                "type": "->",
                "args": [
                    "OCA\\Accountancy\\Controller\\AccountApiController"
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                "line": 465,
                "function": "query",
                "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                "type": "->",
                "args": [
                    "OCA\\Accountancy\\Controller\\AccountApiController"
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                "line": 437,
                "function": "queryNoFallback",
                "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                "type": "->",
                "args": [
                    "OCA\\Accountancy\\Controller\\AccountApiController"
                ]
            },
            {
                "file": "/var/www/html/lib/private/AppFramework/App.php",
                "line": 159,
                "function": "query",
                "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                "type": "->",
                "args": [
                    "OCA\\Accountancy\\Controller\\AccountApiController"
                ]
            },
            {
                "file": "/var/www/html/lib/private/Route/Router.php",
                "line": 298,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::",
                "args": [
                    "OCA\\Accountancy\\Controller\\AccountApiController",
                    "index",
                    {
                        "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
                    },
                    [
                        "1",
                        "accountancy.account_api.index"
                    ]
                ]
            },
            {
                "file": "/var/www/html/lib/base.php",
                "line": 1030,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->",
                "args": [
                    "/apps/accountancy/api/v1/accounts"
                ]
            },
            {
                "file": "/var/www/html/index.php",
                "line": 36,
                "function": "handleRequest",
                "class": "OC",
                "type": "::",
                "args": []
            }
        ],
        "File": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
        "Line": 102,
        "Previous": {
            "Exception": "OCP\\AppFramework\\QueryException",
            "Message": "Could not resolve OCA\\Accountancy\\Service\\AccountService! Class \"OCA\\Accountancy\\Service\\AccountService\" does not exist",
            "Code": 0,
            "Trace": [
                {
                    "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                    "line": 133,
                    "function": "resolve",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Service\\AccountService"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                    "line": 465,
                    "function": "query",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Service\\AccountService"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                    "line": 437,
                    "function": "queryNoFallback",
                    "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Service\\AccountService"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                    "line": 89,
                    "function": "query",
                    "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Service\\AccountService",
                        true
                    ]
                },
                {
                    "function": "OC\\AppFramework\\Utility\\{closure}",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                    "line": 108,
                    "function": "array_map",
                    "args": [
                        {
                            "__class__": "Closure"
                        },
                        [
                            {
                                "__class__": "ReflectionParameter",
                                "name": "appName"
                            },
                            {
                                "__class__": "ReflectionParameter",
                                "name": "request"
                            },
                            "*** sensitive parameters replaced ***",
                            {
                                "__class__": "ReflectionParameter",
                                "name": "userId"
                            }
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                    "line": 116,
                    "function": "buildClass",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        {
                            "__class__": "ReflectionClass",
                            "name": "OCA\\Accountancy\\Controller\\AccountAPIController"
                        }
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
                    "line": 133,
                    "function": "resolve",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Controller\\AccountApiController"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                    "line": 465,
                    "function": "query",
                    "class": "OC\\AppFramework\\Utility\\SimpleContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Controller\\AccountApiController"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
                    "line": 437,
                    "function": "queryNoFallback",
                    "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Controller\\AccountApiController"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/App.php",
                    "line": 159,
                    "function": "query",
                    "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
                    "type": "->",
                    "args": [
                        "OCA\\Accountancy\\Controller\\AccountApiController"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Route/Router.php",
                    "line": 298,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::",
                    "args": [
                        "OCA\\Accountancy\\Controller\\AccountApiController",
                        "index",
                        {
                            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
                        },
                        [
                            "1",
                            "accountancy.account_api.index"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/base.php",
                    "line": 1030,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->",
                    "args": [
                        "/apps/accountancy/api/v1/accounts"
                    ]
                },
                {
                    "file": "/var/www/html/index.php",
                    "line": 36,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::",
                    "args": []
                }
            ],
            "File": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
            "Line": 122
        },
        "CustomMessage": "--"
    }
}

Github link : https://github.com/NicolasDeGheselle/nextcloud-accountancy

Hello,

Did you change the error message in any way?

Please activate the debug mode in your den instance (in the global configuration file). There should be a back trace included, then.

I do not see any obvious does in your code while scanning on my phone. Eventually, my guess was that the file babes are not correctly set. Can you verify these?

Christian

PS: are you by chance developing on a windows machine?

To be exact this message come from the nextcloud.log file, the server just return a 500 without much information. I added the whole stack in my original post.

“file babes” what’s that ?

Yes indeed, I am using docker on Windows. I also added the github link in the original post.

Uups. My phone miss-corrected me. I was referring to the file names.

Regarding the windows issue: make sure the file names are set correctly insides the docker container. I had once problems with the case of the letters as the docker container is using Linux file system conventions.

Sight, it was indeed the file name (AcountService → AccountService). The simplest things are always the hardest to spot right ?

Thanks a lot for the quick responses :smile:

1 Like