From ce433a565e77e58407ea53da3fdcd90fd0307db5 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Fri, 15 Jul 2022 13:11:30 -0700 Subject: [PATCH] chore: Warn and continue when failing to load a spec (#9989) --- lib/google_apis/generator/elixir_generator.ex | 44 ++++++++------- .../generator/elixir_generator/token.ex | 54 +++++++++---------- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/lib/google_apis/generator/elixir_generator.ex b/lib/google_apis/generator/elixir_generator.ex index 33f6196fd5..8bb39b7599 100644 --- a/lib/google_apis/generator/elixir_generator.ex +++ b/lib/google_apis/generator/elixir_generator.ex @@ -37,26 +37,30 @@ defmodule GoogleApis.Generator.ElixirGenerator do """ @spec generate_client(ApiConfig.t()) :: any() def generate_client(api_config) do - token = Token.build(api_config) - if updated_discovery_revision?(token) do - token - |> load_models - |> set_model_filenames - |> update_model_properties - |> create_directories - |> write_model_files - |> load_global_optional_params - |> load_apis - |> set_api_filenames - |> write_api_files - |> write_connection - |> write_metadata - |> write_mix_exs - |> write_readme - |> write_license - |> write_gitignore - |> write_config_exs - |> write_test_helper_exs + case Token.build(api_config) do + nil -> + IO.puts("Unable to read spec file #{ApiConfig.google_spec_file(api_config)}") + token -> + if updated_discovery_revision?(token) do + token + |> load_models + |> set_model_filenames + |> update_model_properties + |> create_directories + |> write_model_files + |> load_global_optional_params + |> load_apis + |> set_api_filenames + |> write_api_files + |> write_connection + |> write_metadata + |> write_mix_exs + |> write_readme + |> write_license + |> write_gitignore + |> write_config_exs + |> write_test_helper_exs + end end :ok end diff --git a/lib/google_apis/generator/elixir_generator/token.ex b/lib/google_apis/generator/elixir_generator/token.ex index 1bc2fff0ad..21593d0417 100644 --- a/lib/google_apis/generator/elixir_generator/token.ex +++ b/lib/google_apis/generator/elixir_generator/token.ex @@ -73,33 +73,33 @@ defmodule GoogleApis.Generator.ElixirGenerator.Token do String.downcase(ApiConfig.module_version(api_config)) ]) - rest_description = - api_config - |> ApiConfig.google_spec_file() - |> File.read!() - |> Poison.decode!(as: %RestDescription{}) - - {base_url, base_path} = determine_base_paths(rest_description) - - resource_context = - ResourceContext.empty() - |> ResourceContext.with_namespace(namespace) - |> ResourceContext.with_base_path(base_path) - - data_wrapped = has_data_wrapper_feature?(rest_description) - - %__MODULE__{ - filename: filename, - library_name: library_name, - namespace: namespace, - root_namespace: root_namespace, - root_dir: root_dir, - base_dir: base_dir, - base_url: base_url, - rest_description: rest_description, - resource_context: resource_context, - data_wrapped: data_wrapped - } + case api_config |> ApiConfig.google_spec_file() |> File.read() do + {:ok, content} -> + rest_description = Poison.decode!(content, as: %RestDescription{}) + {base_url, base_path} = determine_base_paths(rest_description) + + resource_context = + ResourceContext.empty() + |> ResourceContext.with_namespace(namespace) + |> ResourceContext.with_base_path(base_path) + + data_wrapped = has_data_wrapper_feature?(rest_description) + + %__MODULE__{ + filename: filename, + library_name: library_name, + namespace: namespace, + root_namespace: root_namespace, + root_dir: root_dir, + base_dir: base_dir, + base_url: base_url, + rest_description: rest_description, + resource_context: resource_context, + data_wrapped: data_wrapped + } + _ -> + nil + end end defp determine_base_paths(rest_description) do