NameError - unitilaized constant - only in production - ruby

I have a ruby on rails app that is hosted on heroku. When I try to create an item running it in "development" mode, everything works great and there are no issues. However, when I switch the app to run in "production" mode I'm getting the following.
This was a Ruby 2.2.x upgraded to 2.5.x and rails 4.1 upgraded to 5.2.
Any ideas or suggestions on why this is failing in production but works fine in development?
Started POST "/items" for 1.2.3.4 at 2020-10-19 03:22:06 +0000
2020-10-19T03:22:06.870055+00:00 app[web.1]: Processing by ItemController#create as HTML
2020-10-19T03:22:06.870358+00:00 app[web.1]: Parameters: {###Redacted##}
2020-10-19T03:22:06.926046+00:00 app[web.1]: Completed 500 Internal Server Error in 54ms (ActiveRecord: 15.8ms)
2020-10-19T03:22:06.999133+00:00 app[web.1]: I, [2020-10-19T03:22:06.998984 #11] INFO -- : Sending event 18b887c876d4524b5cd46849a98aaeb1 to Sentry
2020-10-19T03:22:07.271068+00:00 app[web.1]:
2020-10-19T03:22:07.271478+00:00 app[web.1]: NameError (uninitialized constant #<Class:0x0000567238d68165>::Slug):
2020-10-19T03:22:07.276183+00:00 app[web.1]:
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:305:in `name_to_slug'
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:293:in `generate_slug'

I tracked this back to a custom class that was located in the "lib" folder. Moving from Rails 4 to 5 it seems like some behaviors changed with loading custom classes which needed to be accounted for:
https://gist.github.com/maxivak/381f1e964923f1d469c8d39da8e2522f

Related

NestJS (Nx workspace) build failing on Heroku

I'm trying to deploy a NestJS app (in Nx workspace) on Heroku, but the deploy is failing with error:
2021-12-24T11:03:17.280952+00:00 app[web.1]: at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Array.forEach (<anonymous>)
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Object.89 (/app/dist/apps/api/main.js:1:4717)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at Object.812 (/app/dist/apps/api/main.js:1:5865)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.424198+00:00 heroku[web.1]: Process exited with status 1
2021-12-24T11:03:17.602083+00:00 heroku[web.1]: State changed from starting to crashed
I have seen some Mongoose issues and they don't seem to be the problem here, since the packages have since gotten multiple updates.
Edit:
After running the app from the Heroku console I got a more explicit error:
/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43
optionsOrType = isClass ? optionsOrType : optionsOrType();
^
TypeError: Class constructors cannot be invoked without 'new'
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43:55)
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:52:39)
at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
at Array.forEach (<anonymous>)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
at Object.89 (/app/dist/apps/api/main.js:1:4301)
at o (/app/dist/apps/api/main.js:1:12011)
at Object.812 (/app/dist/apps/api/main.js:1:5449)
at o (/app/dist/apps/api/main.js:1:12011)
I had the same problem and it was caused by an upgrade of nrwl/nx to 13.3.1.
A downgrade of nrwl/nx to 13.2.4 fixed it.
So it seems that nx 13.3.0 introduced a dependency update which breaks the application.

Weird "is_xhr" error when deploying Flask app to Heroku

I have a flask app which I've deployed to Heroku, one of the routes is the following
def get_kws():
seed_kw = request.json['firstParam']
audience_max = request.json['secondParam']
interest_mining_service = InterestMiningService(seed_kw, audience_max)
query_result = interest_mining_service.query_keyword().tolist()
if seed_kw in query_result:
print ("yes")
return jsonify(
{
'keyword_data' : interest_mining_service.find_kws().to_json(orient='records'),
'query_results': query_result
}
)
When I test this endpoint locally, I have no issues when sending POST and GET requests to that endpoint. However, when I deploy to Heroku, I get the following error:
File "/app/server/controller.py", line 24, in get_kws
2020-02-08T22:31:05.893850+00:00 app[web.1]: 'query_results': query_result
2020-02-08T22:31:05.893850+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/json.py", line 298, in jsonify
2020-02-08T22:31:05.893851+00:00 app[web.1]: if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
2020-02-08T22:31:05.893851+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/local.py", line 347, in __getattr__
2020-02-08T22:31:05.893852+00:00 app[web.1]: return getattr(self._get_current_object(), name)
2020-02-08T22:31:05.893858+00:00 app[web.1]: AttributeError: 'Request' object has no attribute 'is_xhr'
I've never seen this error Request object has no attribute 'is_xhr' before and it only seems to be happening when I deploy to Heroku. Any guidance on what I should look into?
There also doesn't seem to be an issue with the json key keyword_data - the issue seems limited to query_results which is a list.
The Werkzeug library (dependency from Flask) recently received a major update (0.16.1 --> 1.0.0) and it looks like Flask (<=0.12.4) does not restrict the version of Werkzeug that is fetched.
You have 2 options:
Stick with your current version of Flask and restrict the Werkzeug version that is fetched explicitly in your application's setup.py or requirements.txt by specifying werkzeug<1.0 or werkzeug==0.16.1
Upgrade to a recent version of Flask (>=1.0.0), which is running fine with latest Werkzeug
Or you can just forcefully install the bustard again by calling
pip install Werkzeug==0.16.1
I have faced with this problem too.
Just temporarily fixed by directly checking in request header
request.headers.get("X-Requested-With") == "XMLHttpRequest"
not sure this help ...

meanjs 0.4.0 not working when deployed to Heroku

I've just tried the meanjs 0.4.0 in local host and runs fine but when I deploy to heroku link to app and try the "Sign up" option I get this in the navegator console:
POST https://meanjsapptest.herokuapp.com/api/auth/signup 503 (Service Unavailable)
and when I write the comand heroku logs in the CLI I get:
2017-06-06T04:15:35.152983+00:00 app[web.1]: (node:16) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2017-06-06T04:15:35.153005+00:00 app[web.1]: crypto.js:635
2017-06-06T04:15:35.153006+00:00 app[web.1]: throw new TypeError(
2017-06-06T04:15:35.153006+00:00 app[web.1]: ^
2017-06-06T04:15:35.153007+00:00 app[web.1]:
2017-06-06T04:15:35.153008+00:00 app[web.1]: TypeError: The "digest" argument is required and must not be undefined
2017-06-06T04:15:35.153009+00:00 app[web.1]: at pbkdf2 (crypto.js:635:11)
2017-06-06T04:15:35.153010+00:00 app[web.1]: at Object.exports.pbkdf2Sync (crypto.js:628:10)
2017-06-06T04:15:35.153012+00:00 app[web.1]: at model. (/app/modules/users/server/models/user.server.model.js:112:26)
2017-06-06T04:15:35.153011+00:00 app[web.1]: at model.UserSchema.methods.hashPassword (/app/modules/users/server/models/user.server.model.js:123:19)
2017-06-06T04:15:35.153013+00:00 app[web.1]: at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
2017-06-06T04:15:35.153013+00:00 app[web.1]: at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
2017-06-06T04:15:35.153014+00:00 app[web.1]: at model. (/app/node_modules/mongoose/lib/plugins/saveSubdocs.js:20:7)
2017-06-06T04:15:35.153014+00:00 app[web.1]: at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
2017-06-06T04:15:35.153015+00:00 app[web.1]: at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
2017-06-06T04:15:35.153015+00:00 app[web.1]: at /app/node_modules/mongoose/lib/plugins/validateBeforeSave.js:33:13
2017-06-06T04:15:35.153016+00:00 app[web.1]: at /app/node_modules/kareem/index.js:131:16
2017-06-06T04:15:35.153016+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:95:7)
2017-06-06T04:15:35.153017+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:161:9)
2017-06-06T04:15:35.167579+00:00 app[web.1]: error: Forever detected script exited with code: 1
2017-06-06T04:15:35.173500+00:00 app[web.1]: error: Script restart attempt #1
2017-06-06T04:15:35.292903+00:00 app[web.1]:
2017-06-06T04:15:35.294191+00:00 app[web.1]:
2017-06-06T04:15:35.310954+00:00 app[web.1]: + Error: Certificate file or key file is missing, falling back to non-SSL mode
2017-06-06T04:15:35.311037+00:00 app[web.1]: To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh
2017-06-06T04:15:35.311039+00:00 app[web.1]:
2017-06-06T04:15:35.916892+00:00 app[web.1]: Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
I don't know what to do now because Heroku supports tell me thar the error is in my code but I haven't changed anything there!
CLI screenshot
Just had this problem. We were able to fix it by enforcing our preferred node version in package.json > engines.
We previously had it at
"node": ">=0.10.0"
We changed it to
"node": "6.6.0"
And then pushed that to Heroku, and that fixed the issue.
Not entirely sure what the problem is, but we found this link which lead us to believe the node version was the issue:
https://github.com/nodejs/node/wiki/Breaking-changes-between-v4-LTS-and-v6-LTS#crypto

Setting up Sentry in an Elixir app, getting undefined function String.trim/2

I'm following these instructions (https://github.com/getsentry/sentry-elixir) to set up Sentry error notifications in an Elixir/Phoenix app. It works fine in my dev environment, but when I push to production (using Heroku) I get the following error which seems to occur within the Sentry module itself: (UndefinedFunctionError) undefined function String.trim/2.
Here is the full log output:
** (exit) an exception was raised:
2016-12-01T23:14:00.741733+00:00 app[web.1]: ** (UndefinedFunctionError) undefined function String.trim/2
2016-12-01T23:14:00.741736+00:00 app[web.1]: (elixir) String.trim("** (Phoenix.ActionClauseError) bad request to MyApp.UserController.create, no matching action clause to process request", "*")
2016-12-01T23:14:00.741737+00:00 app[web.1]: (sentry) lib/sentry/event.ex:65: Sentry.Event.transform_exception/2
2016-12-01T23:14:00.741738+00:00 app[web.1]: (sentry) lib/sentry.ex:86: Sentry.capture_exception/2
2016-12-01T23:14:00.741739+00:00 app[web.1]: (plug) lib/plug/error_handler.ex:96: Plug.ErrorHandler.__catch__/5
2016-12-01T23:14:00.741740+00:00 app[web.1]: (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
2016-12-01T23:14:00.741741+00:00 app[web.1]: (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.call/2
2016-12-01T23:14:00.741742+00:00 app[web.1]: (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
2016-12-01T23:14:00.741742+00:00 app[web.1]: (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
and when I try to access alias String by logging into the iex via heroku run, I get nil.
Any idea why the String module is undefined in production only?
i think you need to force heroku to use elixir version 1.3.x
If you use the heroku-buildpack-elixir set your elixir version to minimum of 1.3.0
https://github.com/HashNuke/heroku-buildpack-elixir
There is the corresponding issue:
https://github.com/getsentry/sentry-elixir/issues/95

NameError uninitialized constant in Jruy/Rails 3

I'm upgrading a project to Rails 3.1 and Jruby 1.6.4 from rails 2.6 I followed the Rails Handbook by Jeremy.
Now I'm getting some errors while booting the server.
NameError in Adm::AuthController#login
uninitialized constant Sentry::Dispatcher::Dispatcher
The error log
Started GET "/admin/login/en/sentry" for 127.0.0.1 at Wed Oct 05 16:59:00 -0400
2011
Processing by Adm::AuthController#login as HTML
Parameters: {"brand"=>"sentry", "language"=>"en"}
Completed 500 Internal Server Error in 9ms
NameError (uninitialized constant Sentry::Dispatcher::Dispatcher):
lib/sentry/dispatcher/application_dispatcher.rb:11:in `initialize'
app/controllers/application_controller.rb:90:in `before_interceptors'
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.0ms)
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
(5.0ms)
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within re
scues/layout (30.0ms)
This works for me..
while upgrading you need to include the class as well, like(in this case)
include 'sentry/dispatcher/dispatcher'

Resources