When trying to run the Cloud Vision API sample from Ruby for the first time, I encountered the following error:
bundle exec ruby vision_samples.rb labels images/cat.jpg
/usr/local/google/home/class/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-cloud-vision- 0.20.2/lib/google-cloud-vision.rb:106:in `vision': project is missing (ArgumentError)
from /usr/local/google/home/class/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-cloud- vision-0.20.2/lib/google-cloud-vision.rb:63:in `vision'
from vision_samples.rb:25:in `detect_labels'
from vision_samples.rb:120:in `<main>'
To resolve the issue, I commented out lines in the file google-cloud-vision-0.20.2/lib/google-cloud-vision.rb client library:
def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,
timeout: nil
require "google/cloud/vision"
#project ||= Google::Cloud::Vision::Project.default_project
#project = project.to_s # Always cast to a string
#fail ArgumentError, "project is missing" if project.empty?
After commenting out the files, the sample worked, indicating that the project name was not important for what I was doing. Curious to find out whether project was necessary here, I grepped around within the project to see if we ever are using this required parameter:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb:require "google/cloud/vision/project"
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # provide the project and credential information to connect to the Cloud
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # Use {Vision::Project#image} to create images for the Cloud Vision service.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # {Vision::Project#annotate}, below.)
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # (or a string file path or Storage URI) to {Vision::Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # is used on {Project#annotate} as well as {Image#faces}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # This is used on {Project#annotate} as well as {Image#landmarks}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # used on {Project#annotate} as well as {Image#logos}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # is used on {Project#annotate} as well as {Image#labels}.
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Using the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision.rb: # @example Updating the default setting on {Project#annotate}:
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb: # See {Project#annotate}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb: def initialize project
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb: @project = project
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb: # See {Project#annotate} for requests that do not involve multiple
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotate.rb: Image.from_source source, @project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb: attr_accessor :project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb: def initialize project, credentials, retries: nil, timeout: nil
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb: @project = project
google-cloud-vision-0.20.2/lib/google/cloud/vision/service.rb: "#{self.class}(#{@project})"
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation.rb: # See {Project#annotate} and {Image}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/image.rb: # See {Project#image}.
google-cloud-vision-0.20.2/lib/google/cloud/vision/image.rb: # Raise an error unless an active vision project object is available.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # # Project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: class Project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # @private Creates a new Project instance.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # The Vision project connected to.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # gcloud = Google::Cloud.new "my-todo-project",
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # vision.project #=> "my-todo-project"
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: def project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: service.project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: # @private Default project.
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: def self.default_project
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: ENV["VISION_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: ENV["GOOGLE_CLOUD_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: ENV["GCLOUD_PROJECT"] ||
google-cloud-vision-0.20.2/lib/google/cloud/vision/project.rb: Google::Cloud::Core::GCE.project_id
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # mirror projections typical of photos. So `face.features.eyes.left`
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google/cloud/vision/annotation/face.rb: # image, without considering mirror projections typical of photos.
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: # @return [Google::Cloud::Vision::Project]
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: Google::Cloud.vision @project, @keyfile, scope: scope,
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: # @param [String] project Project identifier for the Vision service you are
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: # @return [Google::Cloud::Vision::Project]
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: def self.vision project = nil, keyfile = nil, scope: nil, retries: nil,
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: project ||= Google::Cloud::Vision::Project.default_project
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: project = project.to_s # Always cast to a string
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: fail ArgumentError, "project is missing" if project.empty?
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: Google::Cloud::Vision::Project.new(
google-cloud-vision-0.20.2/lib/google-cloud-vision.rb: project, credentials, retries: retries, timeout: timeout))
As far as I can tell, the project field is not being used anywhere and is not required for this API.
As such, I'm proposing either we update the client library to not exit and instead warn the user if the project name is not specified or we should never use the project field in this client library.
Additionally, in other cases where the client library requires the project but it is unused, we should remove the project name requirement.
When trying to run the Cloud Vision API sample from Ruby for the first time, I encountered the following error:
To resolve the issue, I commented out lines in the file
google-cloud-vision-0.20.2/lib/google-cloud-vision.rbclient library:After commenting out the files, the sample worked, indicating that the project name was not important for what I was doing. Curious to find out whether project was necessary here, I grepped around within the project to see if we ever are using this required parameter:
As far as I can tell, the project field is not being used anywhere and is not required for this API.
As such, I'm proposing either we update the client library to not exit and instead warn the user if the project name is not specified or we should never use the project field in this client library.
Additionally, in other cases where the client library requires the project but it is unused, we should remove the project name requirement.